c/c++中gets()的替代用法

get()在应用中开始被禁用(例如PAT),而scanf()只能输入一段字符串(不含空格),这就使得有一些特定的输入很难完成。
以下是替代的方法:

一、

	string str;
	getline(cin,str);

二、

	char str[maxn];
	fgets(str,maxn,stdin);
	int num=0;
	while(str[num]!='\n') num++;
	str[num]='\0';
原创文章 5 获赞 13 访问量 511

猜你喜欢

转载自blog.csdn.net/china_LBOY/article/details/105285098