0

I want to take input from the user as multiple lines. But when a run the program and write "Hello, my name us umer" here when i enter to write new line. The program runs. I want to write new line. This is my code to read inpput.

string text;

    cout<<"Enter the text"<<endl;
    getline(cin,text);

How i can input muliple line in C++?

1 Answer 1

2

You want to use a loop for multiple lines.

while(getline(cin,line))
{
  cout << line << endl;
  //do something
}
Sign up to request clarification or add additional context in comments.

3 Comments

But my question is how user will run the program? when i enter, the new line comes. How will i know, user enters his all text?
@Umer: When user enter EOF. In linux it's Ctrl-D.
Thanks buddey. Its ctrl+z in windows.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.