I am trying to create a function that displays details of user after they have signed up. Keep getting error about strcmp function.
Note i'm getting from compiler: candidate function not viable: no known conversion from 'std::__cxx11::string' (aka >'basic_string') to 'const char *' for 1st argument
Code:
void display_uDetails(char n[])
{
std::cout<<"\nUSER DETAILS\n";
int flag=0;
fp.open("book.dat",ios::in);
while(fp.read((char*)&u,sizeof(createUser)))
{
if(strcmp(u.retuname(),n)==0)
{
u.show_user();
flag=1;
}
}
fp.close();
if(flag==0)
std::cout<<"\n\nUser does not exist!";
getch();
}
Update:
The error is coming from my retuname() function here:
char* retuname()
{
return uname;
}
Display function:
void display_uDetails(char n[])
{
std::cout<<"\nUSER DETAILS\n";
int flag=0;
fp.open("book.dat",ios::in);
while(fp.read((char*)&cu,sizeof(createUser)))
{
if(cu.retuname() == n)
{
cu.show_user();
flag=1;
}
}
fp.close();
if(flag==0)
std::cout<<"\n\nUser does not exist!";
getch();
}
It says *error: no viable conversion from returned value of type > 'std::__cxx11::string' (aka 'basic_string') to function return type 'char ' return uname; ^~~~~
'cu' Class definition
class createUser
{
string uname;
string pword;
string name;
};
Defining createUser class as 'cu' & declaring stream
// global declaration for stream object, object
fstream fp, fp1;
createUser cu;