C/C++读入含有空格的字符串

版权声明:转载请注明出处,谢谢。 https://blog.csdn.net/Mercury_Lc/article/details/87644554

好久之前遇到 gets()不准用的情况,所以稍稍参考了一下网上的方法,整理一下。 

char st[maxn];
string s;

1、gets(st);

2、scanf("%[^\n]",st);

3、getline( cin, s); // 这里s是 string

4、cin.get(st , maxn);

5、cin.getline(st,maxn);

猜你喜欢

转载自blog.csdn.net/Mercury_Lc/article/details/87644554