Quote:
int check(string username)
{
cin >> username;
string data1, data2;
ifstream infile;
infile.open("profile.txt", ios::app); //<-- What are you going to append to a input file?
getline(infile, data1);
if (username == data1)
{
cout << "Username exits" << endl;
cout << "Enter new username: ";
cin >> username;
return check(username);//<-- it is NOT a good idea to call the function recursively (the file is open again and again)
}
else
{
}
}
My advice: implement the
check
function simply for checking, then ask again (in the calling code) the user to enter the
username if it fails.
My general advice: don't use
goto
, use the
C++
features.