I used \"cin\" to read words from input stream, which like
int main( ){
string word;
while (cin >> word){
//do sth on the input word
Your code is correct. If you were interactively inputting, you would need to send a EOF character, such as CTRL-D.
This EOF character isn't needed when you are reading in a file. This is because once you hit the end of your input stream, there is nothing left to "cin"(because the stream is now closed), thus the while loop exits.