33,311
社区成员
发帖
与我相关
我的任务
分享
#indlue<iostream>
using namespace std;
int main()
{
char str[5];
for(int i=0;i<5;i++)
{
cin>>str[i];
}
for(int j=0;j<5;j++)
{
cout<<str[j];
}
return 0;
}
//C++ CODE
#include<iostream>
#include<string>
using namespace std;
int main(void)
{
string str;
int i=1; //control the loop for convinience
while(i)
{
cin>>str;
if(strlen(str.c_str())<=20)i=0; //repeat while "str" is more than 20 characters.
else cout<<"ERROR!try again!"<<endl; //show information
}
cout<<"Password:"<<str<<endl; //result
return 0;
}
//fgets是对文件操作,应该不能这么直接用,可以这么写:
#include <stdio.h>
#include <string.h>
int main(void)
{
char str[20];
if (scanf("%c",str)!=19)
{
printf("input error!\n");
return 0;
}
printf("The password is:%s \r\n",str);
return 0;
}
int main()
{
char c[20];
scanf("%19s", c);
printf("%s\n", c);
return 0;
}
//这样只能取前19个字符