Compiler Bugs

I am programming with the Code::Blocks IDE and using the GNU GCC compiler. When I create an simple console application that uses strings it kind of glitches out, but here's the code:


#include <iostream>
#include <cstdlib>
#include <string>


using namespace std;

int main()
{
string x;
cout << "Please enter a string of text: ";
cin >> x;
cout << "You entered: " << x;
}

What the output is:

Please enter a string of text: Hello World
You entered: Hello
Process returned 0 (0x0) execution time : 4.735 s
Press any key to continue.

Anyway I don't know why it removes what I typed after the space I put in between Hello and World.
cin stops when it encounters a blank space.

Check into using getline when you want to capture a string that may have multiple words.
http://www.cplusplus.com/reference/string/string/getline/?kw=getline
Topic archived. No new replies allowed.