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:
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:
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,struct std::char_traits<char>,class std::allocator<char> >' to 'const char *'
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

int sameU = strcmp(a.c_str(),u1);
Hi chinese_bunny,
You need to use the c_str member function.

int sameU = strcmp(a.c_str(),u1.c_str());
int sameP = strcmp(b.c_str(),p1.c_str());

The .c_str() method returns the constant char* pointer that the C-Style string functions are looking for.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chinese_bunnyAuthor Commented:
oh my gosh! thank you very much to both of you.  it works like a charm now. 0 errors! <33333
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.