Reading from standard input

Hey Guys,

Just wanted to make sure whether this is the right way to read from standard input and if someone does
./a.out < inp1


For string:
1
2
3
4
string str;
while(cin) { 
   getline(cin,str);
}


I am not sure how it should be for ints. Please let me know

Thanks
You can also use >> operator for input (cin>>x;, where x could be a char, int, float or string). The bad thing about >> is that it stops reading at ' ' character, while getline stops at '\n' only. That means that if you have written several words >> will only read the first of them.
Last edited on
You can also use >> operator for input
Don't use >> with cin, see http://www.cplusplus.com/forum/articles/6046/
Topic archived. No new replies allowed.