C+±015-getline的使用-2020-3-3
cin提供了getline的函数,其格式为:getline(字符串首地址,最大长度);用于将用户输入的字符串存放在"字符串首地址"指定的内存中, 其最大长度不能超过"最大长度"指定的值,该函数的一个用处是可以读入一行带空格的字符串,当然gets()函数也能达到同样效果。
//getline的使用
#include<iostream>
using namespace std;
int main()
{
char a[80];
cin.getline(a,80);
cout<<a<<endl;
return 0;
}
hello world
hello world
--------------------------------
Process exited with return value 0
Press any key to continue . . .