<< Forked from http://www.daniweb.com/forums/thread40942.html >>

>But after printing the last word, it just hangs like as if expecting another string too.
Probably because it's expecting another string. A newline is whitespace too, and unless you're terminating the loop with Ctrl+Z (or a read error occurs), it'll just keep asking you for another string. If you want to simply type the line and have the program "do the right thing", you shouldn't use cin's >> operator. Instead, a combination of getline and stringstream will do what you want:

if ( getline ( std::cin, query ) ) {
  std::stringstream ss ( query );
  std::string token;

  while ( ss>> token )
    std::cout<< token <<'\n';

i used the ff. codes from this thread like this:

getline(std::cin, name);
cout<<"Thanks " <<name << " !\n";

but i get the same problem that waits a char input before the next line executes. i am a little confused of the codes at the top, i was not able to apply that to my basic syntax. can u pls help me? :) Thanks a lot!