chinese_bunny
asked on
Converting from CString to String and char array string needed to yield the same string type
I have converted a couple of char array to string like this:
code:
char username_in[20];
char password_in[20];
std::string a((char*) username_in);
std::string b((char*) password_in); //this part compiled fine
I have convereted a couple of CString to String like this:
code:
DDX_CBString(pDX, IDC_Username, L_username);
DDX_CBString(pDX, IDC_Password, L_password);
std::string u1((LPCTSTR)L_username);
std::string p1((LPCTSTR)L_password); //this part compiled fine
But when I try to do a string compare like this:
int sameU = strcmp(a,u1);
int sameP = strcmp(b,p1);
it gives me the error that the two types i'm trying to pass into the strcmp are not the same.
I'm confused because I thought i had changed both of the types to strings so that i can compare them.
So there is probably something wrong with my conversion but I'm not sure what...
This is the error I'm getting:
{
error C2664: 'strcmp' : cannot convert parameter 1 from 'class std::basic_string<char,str uct std::char_traits<char>,cla ss std::allocator<char> >' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
}
code:
char username_in[20];
char password_in[20];
std::string a((char*) username_in);
std::string b((char*) password_in); //this part compiled fine
I have convereted a couple of CString to String like this:
code:
DDX_CBString(pDX, IDC_Username, L_username);
DDX_CBString(pDX, IDC_Password, L_password);
std::string u1((LPCTSTR)L_username);
std::string p1((LPCTSTR)L_password); //this part compiled fine
But when I try to do a string compare like this:
int sameU = strcmp(a,u1);
int sameP = strcmp(b,p1);
it gives me the error that the two types i'm trying to pass into the strcmp are not the same.
I'm confused because I thought i had changed both of the types to strings so that i can compare them.
So there is probably something wrong with my conversion but I'm not sure what...
This is the error I'm getting:
{
error C2664: 'strcmp' : cannot convert parameter 1 from 'class std::basic_string<char,str
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER