I am attempting to write a simple login form. I want to store the list of login accounts in a STL map.
when retrieving text values from text boxes on the form. The boxes return "String^"
So what I have is:
map <String^, String^> NamePassList;
typedef pair<String^, String^> StringPair;
string line, usrName, password;
usrName = password = "";
ifstream ifs("login.in");
if (ifs.is_open()){
while (!ifs.eof()){
getline(ifs,line);
bool endofusername = false;
for (int i = 0; i < line.length(); i++){
if (line[i] == ' '){
endofusername = true;
}
if (!endofusername){
usrName += line[i];
}
else{
password += line[i];
}
}
String ^ temp1 = gcnew String(usrName.c_str());
String ^ temp2 = gcnew String(password.c_str());
NamePassList.insert(StringPair(temp1, temp2));
}
ifs.close();
}
String ^ UserName = txtUserName->Text;
String ^ Password = txtPassword->Text;
map<String^, String^>::iterator nameItor;
nameItor = NamePassList.find(UserName);
if (nameItor->first == UserName){
if (nameItor->second == Password){
MessageBox::Show("Sucsess!", "log", MessageBoxButtons::OK);
}
else
MessageBox::Show("Fail!", "log", MessageBoxButtons::OK);
}
else
{
MessageBox::Show("Fail!", "log", MessageBoxButtons::OK);
}
when compiled the error i get of from the "map class" and utility.
This seams like the best way to do it, but everything I try gives me a new error.
Any help would be great!! thanks all.