1、字符串数组,只需输入一行
char str[50];
scanf("%[^\n]",str); //不会吞字符串开头空格
scanf(" %[^\n]",str); //会吞字符串开头空格
2、字符串数组,输入多行
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int maxn=10e6+20;
char s[maxn][10];
char s1[20];
int main(){
for(int i=0;i<3;i++){
scanf("%[^\n]",s[i]);
getchar(); //必须加,清楚上一行字符串末尾的回车和空格
}
for(int i=0;i<3;i++)
printf("%s\n",s[i]);
return 0;
}
2万+

被折叠的 条评论
为什么被折叠?



