阅读量:75
是的,C++中的cin.getline函数能够接收空格。cin.getline函数可以读取一行输入,包括空格字符,直到遇到换行符为止。因此,它可以用来接收包含空格的字符串输入。示例代码如下:
#include
using namespace std;
int main() {
char str[100];
cout << "请输入包含空格的字符串:" << endl class="hljs-built_in">getline(str, 100);
cout << "您输入的字符串是:" << str class="hljs-keyword">return 0;
}
运行该程序时,可以输入包含空格的字符串,例如"Hello World",然后程序会将整个字符串作为输入,并输出相同的字符串。