I'm unable to convert a char
to an int
and I have no idea why.
I simply want to convert some data that I parse from a CSV from string
to int
and the compiler won't let me.
I get this error:
invalid cast from type '__gnu_cxx::__alloc_traits<std::allocator<std::__cxx11::basic_string<char> > >::value_type {aka std::__cxx11::basic_string<char>}' to type 'int'
Note I have also tried:
static_cast<int>(data[2]);
and even
'a' - data[2];
Am I missing something? I feel like I've done this a million times.
time_t startDate;
string ID;
int beds;
int numDays;
string token;
vector<string> data;
for(int i = 0; i < 2; i++){ // run through the rest of the file
getline(customers, line);
stringstream s(line); // to parse the csv
while(getline(s,token, ',')){
data.push_back(token);
}
startDate = changeToInt(data[0]);
ID = data[1];
---> beds = (int)data[2];
---> numDays = (int)data[3];