-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