c++问题,帮我看看哪错了
#include<stdio.h>#include<conio.h>#include<iostream.h>#include<string>usingnamespaces...
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <string>
using namespace std;
class manager
{
string ID;
string password;
string popedom;
string passwords;//second
public:
inline bool manager::Changepassword()
{
int i;
cout<<"输入新密码,按回车结束:(1--10个字符)\n";
cout<<"Input the new password,end with 'enter'\n";
for (i=0;i<password.size();i++)
{
password[i]=getch();
cout<<"*";
if (password[i]=='\r'&&i>0&&i<10)
break;
else cout<<"error!Out of Rang(1--10)";
}
password[i]='\0';
passwords=password;
return true;}
inline bool manager::Makesurepassword()
{
cout<<"\n再次输入确认密码:\n";
cout<<"\nmake sure the changes:\n";
do
{
for (int i=0;i<passwords.size();i++)
{
password[i]=getch();
cout<<"*";
if (password[i]=='\r')
break;
}
password[i]='\0';
if (password.compare(passwords)==0)
{cout<<"\nPassword is OK!\n";
break;}
else
if (password.compare("quit\r")==0) break;
else
cout<<"\n密码检验错误,输入quit退出\n";
cout<<"\nwrong!enter 'quit' to exit." ;
}
while (1);
return true;
} //make sure the password
};
void main()
{manager A;
A.Changepassword();
A.Makesurepassword();
} 展开
#include <conio.h>
#include <iostream.h>
#include <string>
using namespace std;
class manager
{
string ID;
string password;
string popedom;
string passwords;//second
public:
inline bool manager::Changepassword()
{
int i;
cout<<"输入新密码,按回车结束:(1--10个字符)\n";
cout<<"Input the new password,end with 'enter'\n";
for (i=0;i<password.size();i++)
{
password[i]=getch();
cout<<"*";
if (password[i]=='\r'&&i>0&&i<10)
break;
else cout<<"error!Out of Rang(1--10)";
}
password[i]='\0';
passwords=password;
return true;}
inline bool manager::Makesurepassword()
{
cout<<"\n再次输入确认密码:\n";
cout<<"\nmake sure the changes:\n";
do
{
for (int i=0;i<passwords.size();i++)
{
password[i]=getch();
cout<<"*";
if (password[i]=='\r')
break;
}
password[i]='\0';
if (password.compare(passwords)==0)
{cout<<"\nPassword is OK!\n";
break;}
else
if (password.compare("quit\r")==0) break;
else
cout<<"\n密码检验错误,输入quit退出\n";
cout<<"\nwrong!enter 'quit' to exit." ;
}
while (1);
return true;
} //make sure the password
};
void main()
{manager A;
A.Changepassword();
A.Makesurepassword();
} 展开
1个回答
展开全部
inline bool manager::Changepassword()
{
int i;
cout<<"输入新密码,按回车结束:(1--10个字符)\n";
cout<<"Input the new password,end with 'enter'\n";
for (i=0;i<password.size();i++) /*password为空,.size() = 0,不会循环耶*/
{
password[i]=getch();
cout<<"*";
if (password[i]=='\r'&&i>0&&i<10)
break;
else cout<<"error!Out of Rang(1--10)";
}
password[i]='\0';
/*这里,string类型的
password还是空的啊,必须对它初始化,如password="1234567890"
*/
passwords=password;
return true;}
//////////////////////////////
还有一个问题是,cout是带输入缓冲的,最好在未尾加个endl将缓冲区清空,或者用fflush(stdin),你再改改吧。
请参考这个
http://www.programfan.com/club/old_showbbs.asp?id=128732
inline bool manager::Changepassword()
{
password="1234567890";
int i;
cout<<"输入新密码,按回车结束:(1--10个字符)"<<endl;
cout<<"Input the new password,end with 'enter'"<<endl;
// printf("Input the new password,end with 'enter'\n");
for (i=0;i<password.size();i++)
{
password[i]=getch();
cout<<"*";
fflush(stdin);
// printf("*");
if (password[i]=='\r'&&i>0&&i<10)
break;
else
cout<<"error!Out of Rang(1--10)"<<endl;
}
password[i]='\0';
passwords=password;
return true;}
{
int i;
cout<<"输入新密码,按回车结束:(1--10个字符)\n";
cout<<"Input the new password,end with 'enter'\n";
for (i=0;i<password.size();i++) /*password为空,.size() = 0,不会循环耶*/
{
password[i]=getch();
cout<<"*";
if (password[i]=='\r'&&i>0&&i<10)
break;
else cout<<"error!Out of Rang(1--10)";
}
password[i]='\0';
/*这里,string类型的
password还是空的啊,必须对它初始化,如password="1234567890"
*/
passwords=password;
return true;}
//////////////////////////////
还有一个问题是,cout是带输入缓冲的,最好在未尾加个endl将缓冲区清空,或者用fflush(stdin),你再改改吧。
请参考这个
http://www.programfan.com/club/old_showbbs.asp?id=128732
inline bool manager::Changepassword()
{
password="1234567890";
int i;
cout<<"输入新密码,按回车结束:(1--10个字符)"<<endl;
cout<<"Input the new password,end with 'enter'"<<endl;
// printf("Input the new password,end with 'enter'\n");
for (i=0;i<password.size();i++)
{
password[i]=getch();
cout<<"*";
fflush(stdin);
// printf("*");
if (password[i]=='\r'&&i>0&&i<10)
break;
else
cout<<"error!Out of Rang(1--10)"<<endl;
}
password[i]='\0';
passwords=password;
return true;}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询