-2
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
string checkpass(string password1)
{
string rightpass = "aimen";
string errormsg2;
if (password1 == rightpass)
{
errormsg2 = "Right";
}
else{errormsg2 = "No";}
return errormsg2;
}
int main()
{
string password;
string errormsg;
cout << "Type the password";
loop:
getline (cin,password);
errormsg == checkpass(password);
if (errormsg=="Right")
{
cout << "Admitted" << endl;
}
else {
goto loop;
}
system("pause");
return 0;
}
コンソールに「Admitted」と表示されません。それは始まりますが、私がコンソールの言葉を入れた後、繰り返し何も起こりません。ループを作成する際の問題
私はあなたの援助を要求します。ありがとうございました。
gotoは一般的に眉をひそめます。これに関する議論については、http://stackoverflow.com/questions/3517726/what-is-wrong-with-using-gotoを参照してください。おそらく、whileループが良いでしょう。 – Ian