Need to get data in .dat and convert it into System::string
I am trying to make a log in system which load data from a .dat
So i have a part of code below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
if(radioButton1->Checked) //Login
{
String ^ userAC = textBox1->Text;
String ^ userPW = textBox2->Text;
char ACc[300];
char PWc[300];
bool OK=false;
ifstream inFile("Login System.dat", ios::in);
if (!inFile)
{
MessageBox::Show("File could not be opened\nError code: 4", "Error", MessageBoxButtons::OK);
inFile.close();
}
else
{
while(inFile>>ACc>>PWc)
{
/**/
string AC(ACc);
string PW(PWc);
String ^ ACstr;
String ^ PWstr;
MarshalString(ACstr,AC);
MarshalString(PWstr,PW);
/**/
if (userAC==ACstr && userPW==PWstr)
{
OK=true;
MessageBox::Show("Welcome Back!\n"+ACstr,"Login",MessageBoxButtons::OK);
break;
}
}
if (OK==false)
{
MessageBox::Show("Cannot login\nIncorrect Username or Password", "Login", MessageBoxButtons::OK);
}
}
}
|
I built it and it is a success but when i run it,
it have error:
Debug Assertion Failed!
Program:....
File:....\Microsoft Visual Studio 10.0\VC\include\xstring
Line: 930
Expression: invalid null pointer
.......
I have no idea what is going wrong so i try to comment some part to debug
I found that it come form the code
1 2 3 4 5 6
|
string AC(ACc);
string PW(PWc);
String ^ ACstr;
String ^ PWstr;
MarshalString(ACstr,AC);
MarshalString(PWstr,PW);
|
I tried to use std::string and System::string when getting data from .dat but it failed so i tried char allay
And i just want to find a way to finish this thing with by any mean
I have found the problem
MarshalString can only convert System::string to std::string
I have used it wrongly
1 2
|
String ^ AC = gcnew String(AC.c_str())
String ^ PW = gcnew String(PW.c_str())
|
This can save the day.
Just to note: This is not C++. It is C++/CLI: Microsoft created language which is different from C++.
You are unlikely to get help on it here, but you can try your luck in Windows Programming if you want.
Topic archived. No new replies allowed.