Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading in a line from cout

Status
Not open for further replies.

UNH1995

Technical User
Nov 20, 2001
5
0
0
US
I am trying to read a line of input into a vector. I want to stop adding to the vector when the end of the line is reached. I have tried this:

string word;
vector<string> sv;

cout << &quot;Type a sentence containing 6 words:&quot;;
cin >> word;
while (word != &quot;\n&quot;)
{
sv.push_back(word);
cin >> word;
}

This doesn't seem to work. None of the lines below this code get executed for some reason. I changed the &quot;\n&quot; to &quot;.&quot; and put in the . at the end of the line of input and that wroked just fine. I guess I can't figure out how to recognize the ond of line for the while loop. Thanks
 
use cin.getline(buffer,buffer_lenght)

buffer is an array of characters

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top