I was comparing two strings, but unfortunately this error occurred
error: cannot convert 'std::__cxx11::string' {aka 'std::__cxx11::basic_string<char>'} to 'const char*' line 23
#include <iostream>
#include <string.h>
using namespace std;
class car {
public:
int feulcp, batterycp, length, height, width, seater, torque, power, temp;
char ownername[20], noplate[12], statecheck[20];
string statename[28] = {"andhra pradesh", "arunachal pradesh", "assam,bihar", "chhattisgarh", "goa", "gujarat", "haryana", "himachal pradesh", "jharkhand", "karnataka", "kerala", "madhya pradesh", "maharashtra", "manipur", "meghalaya", "mizoram", "nagaland", "odisha", "punjab", "rajasthan", "sikkim", "tamil nadu", "telangana", "tripura", "uttarakhand", "uttar pradesh", "west bengal"};
car() {
cout << "Please Enter Your State Name: ";
y:
cin >> statecheck;
for(int i=0; i<=27; i++) {
temp = strcmp(statename[i], statecheck); // Here is the error!!!
if(temp == 0) {
goto x;
}
else
cout << "INVALID STATE NAME \n PLEASE RE-ENTER ";
goto y;
}
x:
cout << "successful";
}
};
int main() {
car car1;
return 0;
}
c_str()member function ofstd::stringto get achar*that is usable bystrcmp. But there are other issues in your code (probably typos) - please try to tidy up your post.gotostatements in C++, ask yourself what happens if the entered state text does not match the very first in the list. How will your code ever test it against the second in the list? Or the third?#include <string>, there is nostd::stringformally dictated. If you're using thestd::stringclass, you must include<string>. There are no exceptions, and if it appears to work, that just means you rolled the dice and you auto tires didn't flatten.