getline

Jul 25, 2010 at 2:07pm
Hi . everyone. i have problem with getline()
int main()
{
int count = 1;
string word;
while(count <=2 )
{
cout << count;
getline(cin,word,':');

++count;
}
cout << word;

}
my problem is variable word store last word for example
I Enter

redhat
suse
but the output just suse
Jul 25, 2010 at 2:16pm
Well, what do you expect?
If you want to output every word, you'll have to move the print statement into the loop.
Jul 25, 2010 at 3:09pm
std::getline() replaces the string every time it is called.
Topic archived. No new replies allowed.