getline

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
Well, what do you expect?
If you want to output every word, you'll have to move the print statement into the loop.
std::getline() replaces the string every time it is called.
Topic archived. No new replies allowed.