I am reading ‘generic programming and the stl’
in chapter1, this is a sample like this,
int main()
{
vector<string> v;
string tmp;
while(getline(cin,tmp)) //problem is here, it keep asking me to input value
v.push_back(tmp);
sort(v.begin(), v.end());
copy(v.begin(), v.end(), ostream_iterator<string>(cout,"\n"));
return 0;
}
how do I get out of the while, it keep asking me to input value, no ending….
Send an end-of-file character: you can use CTRL-Z Return (Windows), or CTRL-D (Unix terminals). Then,
getlinewill return false as there is nothing more to read fromstdin.An alternative is: pipe the output of another program into this one.