Hi,sir.I encounterred a person who said that C++ is an unsafe language.I try the follow code ,but when I input an non-int type,the program will fall in a bad loop.(gcc4.1 in Linux)
#include <iostream>
#include <string>
using namespace std;
class bot
{
private:
int password;
public:
bot():password(567){}
virtual ~bot(){};
bool checkpwd(const int pwd)
{return (password == pwd);}
};
int s;
bot b;
int main()
{
for(;;)
{
cout<<"Enter password:";
cin>>s;
if(b.checkpwd(s))
{
cout<<"Access permitted"<<endl<<endl;
break;
}
else
cout<<"Access denied"<<endl<<endl;
}
return 0;
}
I wanner whether the type int is unsafe or the C++'s object in unsafe? If I use string type to define the password,there won't be this error.And I know that this code is not a good C++ program,for testing this problem,so I do it.
Help me,please^_^
Thank you very much!