C++ 控制台输入

2024-12-29 11:45:49
推荐回答(1个)
回答1:

cin默认会略过空格的,可以用getline()

#include
#include

using namespace std ;

int main()
{
string s1;
cout << "Enter a sentence (use <换行符> as the delimiter): ";
getline(cin,s1, '\n');
cout << "You entered: " << s1 << endl;;
}