可以这样直接输入数组么??

来源:百度知道 编辑:UC知道 时间:2024/06/06 20:31:38
#include<iostream>
#include<windows.h>
using namespace std;
main()
{
char rppw[11];
char pw[11];
int lth;
cin>>pw;
lth=strlen(pw);
if (lth>9 || lth<6);
{
cout<<"too short";
system("pause");
exit(0);
}
我的问题是cin>>pw; 对吗,可以这样直接输入吗??请祥解~~

你的程序是可以的,只是if后面多了个分号“;”,后面又少了个}号.
不像一楼说得只能输入一个字符,也不想二楼说得有那么多错误。就是2个标点的问题。
下面是改过的程序,你可以比较一下

#include<iostream>
#include<windows.h>
using namespace std;
main()
{
char rppw[11];
char pw[11];
int lth;
cin>>pw;
cout<<pw<<endl;
lth=strlen(pw);
if (lth>9 || lth<6)
{
cout<<"too short";
system("pause");
exit(0);
}
}
注意这个程序你只能输入11个字符,否则就不能保证程序的正确,因为你的char pw[11]数组大小就是11。

整个程序,有好多多小错误,汗!都不知道楼主怎么运行的.不过就cin而言是可以的,这也是c++"流"操作的跟c语言不同的特色之一,当然你要输出这个数组,cout后直接接数组名即可,如cout<<pw.
下面有个小程序,楼主可以试试.
#include "stdafx.h"
#include "iostream.h"
#include "string.h"
void main()
{
char pw[11];
int lth;
cin>>pw;
lth=strlen(pw);
if (lth<6){
cout<<"too short"<<endl;
cout<<