cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Compiler Bugs
Compiler Bugs
Jun 9, 2014 at 1:57pm UTC
Rocker98585
(3)
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.
Jun 9, 2014 at 2:03pm UTC
wildblue
(1505)
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.