How to take multiple line string in c++?

I want to take multiple line string in c++. How can I take this.

Such as I want to take this as input:

HELLO MY LOVE, I M HAPPY BECAUSE SOON I WILL BE TO YOUR SIDE. THIS
TIME WITHOUT YOU HAS BEEN ETERNAL. I INVITE YOU TO THE ZOO ONE TO
SEE THE ZEBRAS AND GORILAS.



Please help how can I do this.
It would be something like this:
1
2
3
4
5
6
std::string Para = " ";

while(std::istream::getline(std::cin, Para))
{
    //Do something here
}



Something else...
1
2
3
std::string temp = " ";
while (std::istream::getline(std::cin, temp))
      Para += temp;


or

1
2
3
std::string temp = " ";
while (std::istream::getline(std::cin, temp))
      Para.append(temp);



C:

1
2
3
4
5
char Str[1024];
while (scanf("%s", Str))
{
     //Do something
} 


etc
Last edited on
1
2
3
4
5
6
std::string Para = " ";

while(std::istream::getline(std::cin, Para))
{
    //Do something here
}


for this the program terminate when newline encounters but my input set has multiple lines

1
2
3
std::string temp = " ";
while (std::istream::getline(std::cin, temp))
      Para += temp;

this code can do my job, it holds the characters into another array.

third also does the same thing as the second

1
2
3
4
5
char Str[1024];
while (scanf("%s", Str))
{
     //Do something
} 


final one works almost same as the first , but this doesn't count space.

By the way , I am using the second code , thank you :)

Topic archived. No new replies allowed.