この関数は、ファイルの各行を読み取り、それをユーザー入力文字列と比較して、一致するかどうかを確認することになっています。基本的に、ファイル内の情報の重複を防ぎます。とにかく、プログラムは「if (loginsFile.is_open())」ステートメントに入らず、その理由がわかりません。
fstream loginsFile;
loginsFile.open("C:/logins.txt", ios::in | ios::out | ios::trunc | ios :: app | ios:: ate);
string username;
string password;
string info;
bool exists = true;
CheckingAccount cA;
SavingsAccount sA;
do {
cout << "Enter Username: ";
cin >> username;
cout << "Enter Password: ";
cin >> password;
cout << endl;
info = username + " " + password;
if (loginsFile.is_open()){
while (loginsFile.good()){
string line;
getline(loginsFile, line);
cout << "line is " << line.substr(line.find_last_of(" ")) << "\n" << "info is " << line.substr(line.find_last_of(" "));
if (line.substr(line.find_last_of(" ")) == info.substr(0, info.find_last_of(" "))){
exists = false;
cout << "Username already exists!" << endl << "Program is not case sensitive!";
} //end if
} //end while
} //end if
} while (exists == true); //end do while
loginsFile << info << endl;
loginsFile.close();
logins[info] = make_pair(cA, sA);
cout << info.substr(0, info.find(' ')) << " Has Been Successfully Registered!" << "\n" << "\n";
return logins;