![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use getline() in C++ when there are blank lines in input?
In C++, we use the getline() function to read lines from stream. It takes input until the enter button is pressed, or user given delimiter is given. Here we will see how to take the new line character as input using the getline() function. Let us see the following implementation to get the idea.
Example
#include<iostream> using namespace std; int main() { string str; int term = 4; while (term--) { getline(cin, str); while (str.length()==0 ) getline(cin, str); cout << str << " : New Line" << endl; } }
Output
Hello Hello : New Line World World : New Line This is This is : New Line C++ Language C++ Language : New Line
Advertisements