tags:

views:

190

answers:

2
string s;
getline(cin,s);

while (HOW TO WRITE IT HERE?)
{
 inputs.push_back(s); 
 getline(cin,s);
}
+7  A: 

Since I'm too lazy to give a full answer today, I'll just paste what the really useful bot in ##c++ on Freenode has to say:

Using "while (!stream.eof()) {}" is almost certainly wrong. Use the stream's state as the tested value instead: while (std::getline(stream, str)) {}. For further explanation see http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.5

In other words, your code should be

string s;

while (getline(cin, s))
{
    inputs.push_back(s);    
}
coppro
+1. One of the (sadly few) times in C++ where the right choice is straightforward and idiomatic.
j_random_hacker
A: 
string s;
getline(cin,s);

while (!cin.eof)
{
        inputs.push_back(s);    
        getline(cin,s);
}
Tom
Yes it works and yes it answers the question as stated, but I like coppro's much better I'm afraid. As well as being simpler and more maintainable, coppro's answer will correctly exit if some other I/O error occurs.
j_random_hacker
You are right. I didnt got past the "know when its eof" part.
Tom