Trying to read in multiple lines into a string variable

So I have a text file like this:
_________________________
Joe
Jim
Hello Jim,

Just wanted to say hello!

-Jim
EOF
Tom
Tim
Hello Tim,
Just wanted to say hello!

-Tim
EOF
__________________________

So the text file stores messages from a system. The first line is the sender, second line is recipient, third line is subject, and 4th line until "EOF" string is the message body.

So I was able to use getline to store the names and subject into variables, but I'm not sure what to use to store the message body as a single string variable.

So obviously, I need a condition that states to read until it gets to "EOF", then store everything before that into a string. Not sure how to do this in C++ though :(

Please help :D Thanks!

Last edited on
A while loop and std::getline.
example code? Wouldn't that have the body in multiple variables though?

While (getline(fin, body) != "EOF")
{
getline...
}
eh?
bump? I've been sitting in my computer lab at school waiting for an answer :(
It is Friday night; it isn't that desperate. Also, I am not doing your work for you.

And it would be like what is on the parashift faq section on iostreams.
It's due by the end of the night. Sorry I didn't mean to sound rude, just can't figure out how getline can put more than one line in a variable. I'm not asking for my work to be done, this is a small part of a big assignment. I'm asking for an example of actually how to use it.

I tried this:

while (messageBody != "EOF")
{
getline(fin, messageBody);
}
But yeah, all that does is keep changing the messageBody variable until it's EOF, I figured maybe something I could do to append it to the end of the string, but I dunno. I thought this was something simple :(
std::string str1, str 2;

std::getline(file, str2);
str1+=str2;
Thanks! Append worked, I tried adding strings together but kept getting errors, oh well, it works so it's all good. Thanks :D
Topic archived. No new replies allowed.