String Help?

Can someone help me to understand how to take cin>> variable; and get it to recognize the spaces in a string?
Thank you!
The insertion operator always skips spaces(white space characters to be precise) regardless. This is the same case with scanf() function in c.

Usually if you want to retrieve the spaces, you retrieve the whole line.

This is commonly done with the getline() function.

1
2
3
std::string line;

getline(std::cin, line);
One thing I've done is use std::replace() to replace spaces with pipes "|" prior to sending the string via a winsock connection and the inverse on the client side with recv() and replace() in a while loop to parse the pipes in the buffer before outputting to std::cout to turn the pipes back into spaces. If you're using fstream for file i/o as Vince1027 mentioned getline() is great.
Thank you both very much for your help!
Topic archived. No new replies allowed.