由於'std :: string'沒有名爲'username'的成員錯誤,所以我的代碼不能編譯。我使用的是code :: blocks。我猜這個問題是因爲我試圖給一個類指定一個字符串,有人可以幫忙嗎?'std :: string'沒有名爲'username'的成員錯誤
#include <iostream>
#include <string>
using namespace std;
class userx
{
public:
string username;
string password;
};
int main()
{
userx X, Y;
X.username = "X";
X.password = "1234";
Y.username = "Y";
Y.password = "5678";
string a;
string b;
cout << "What is your name?" << endl;
cin >> a;
if (a.username == a)
{
cout << "What is your password?" << endl;
cin >> b
if (a.password == b)
{
cout << "Password Accepted" << endl;
};
};
};
如果你使用了正確的變量名,這個bug可能會被避免。 X,Y,a和b完全不會告訴你變量代表什麼。 – Atuos 2014-10-01 11:19:01