Strings with spaces? 字串符带空格
This is my program:这是我的程序
#include <iostream>
using namespace std;
int main()
{
string name;
cout << "Welcome, What is your name?" << endl;
cin >> name;
cout << name << endl;
}
When you enter strings with a space, it doesn't print out the part of the string after the space. Why? I'm pretty new to C++ and I can't figure this out.
当你输入带有空格字符串时,它不能输出空格后面的字符串.为什么?C++很东西我不是很明白
Disch (4163) Jan 7, 2011 at 10:02am
Because >> stops at whitespace.
因为>>因空格停止
If you want the whole line, use getline:
如果你想输出整行,用getline
// cin >> name; // bad
getline(cin,name); // good
有什么建意可以发表一下