strcmp not working

I use GCC compiler(4.6.2) with Code::Blocks IDE. Iwrote the following code for password check-
#include <iostream>
#include<cstdlib>
#include<cstring>
#include<conio.h>

int main()
{
system("clear");
std::string a="";
std::string b="vitaminc";
char c;
for(int i=0;i<1000;i++)
{
c=getch();
if(c=='\r')
break;
std::cout<<"*";
a[i]=c;
}
int d=0;
d=strcmp(a,b);
if(d==0)
std::cout<<"Password Matched!!!";
else
std::cout<<"Password Incorrect!!!";
return 0;
}

After building i get an error saying-
cannot convert 'std::string {aka std::basic_string<char>}' to 'const char*' for argument '1' to 'int strcmp(const char*, const char*)'|
Can anyone tell me what is the problem with this code?
Yes. Use c_str() member to convert a std::string to a const char*, like this:
d=strcmp(a.c_str(),b.c_str());

However, for std::string you can use overloaded == operator:
d = (a == b);
http://www.cplusplus.com/reference/string/string/operators/
variables 'a' and 'b' are std::string types, and the stdlib function strcmp takes const char* types. Try:

 
a.compare(b)

Thank you so much @modoran...it solved the problem!!!!
Topic archived. No new replies allowed.