c++ - Invalid input for std::cin -


the following code intended concatenate words entered user.

#include <iostream> #include <string>   int main() {     // insert code here...      std::string s;     std::string concstring;     while (std::cin >> s)     {         concstring = concstring + s;     }     std::cout << concstring << std::endl;     return 0; } 

i stuck in while loop during execution because of not able print concatenated string. how exit loop? invalid input std::cin?

typically, loop stopped end of file, rather invalid input.

in *nix environment, can send end of file terminal ctrl+d, , @ windows console, ctrl+z.

see https://stackoverflow.com/a/16136924/1084944

you could, however, implement own additional way signify end of input. example, having users enter blank line when done, or word quit or such. once you've chosen one, should communicate user, , have structure loop able detect these conditions , exit.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -