int number;
cout<<"How many product would you like to enter?: ";
cin>>number;
string *arr;
arr = new string[number];
for(int j=0;j<sayi;j++)
{
cout<<j<<". product?: ";
cin>>arr[j];
if ((strcmp(arr[j],"Apple")!=0)&&(strcmp(arr[j],"Orange")!=0)&&(strcmp(arr[j],"Carrot")!=0)){
cout<<"Invalid Product"<<endl;j--;
return;
}
}
That code part gives error on "IF" line. Can someone tell me what is the problem here? and what I should do? Thanks in advance...
error: cannot convert 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >' to 'const char*' for argument '1' to 'int strcmp(const char*, const char*)'|
It's telling you that the std::string given to the first parameter of std::strcmp() isn't compatible with char *. This can be fixed by invoking std::string::c_str() whenever you pass a std::string object to std::strcmp().