在C++编程语言中,为了读入一个带有空格的字符串,我们可以采用 getline
函数,使用示例如下:
#include <iostream>
using namespace std;
int main() {
string s;
getline(cin, s);
cout << s << endl;
return 0;
}
结果如下:
在C++编程语言中,为了读入一个带有空格的字符串,我们可以采用 getline
函数,使用示例如下:
#include <iostream>
using namespace std;
int main() {
string s;
getline(cin, s);
cout << s << endl;
return 0;
}
结果如下: