I am learning C++. I want to take multiple line string as input but I can't. I am using getline() for it but it is taking only one line input. When I press enter for writing next line it stoped taking input and print the first line.
I want to give input like the example below
Hello, I am Satyajit Roy.
I want to make a program.
I love to travel.
But it takes only the first line input.
My code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s;
getline(cin, s);
cout << s << endl;
return 0;
}
Please help me to know how can I do that. Thank you.
while (getline(cin, s)) cout << s << endl;?getlineoptionally takes a delimiter as parameter. How do you know when input is finished? Is it always 3 lines?std::cinit's CTRL-Z (CTRL-D respectively), for file based input it's EOF, no?