I started to study c ++ now and I do not quite understand it yet. I need to get a lot of information on each line of a string vector, so I thought I'd use sscanf
, however I'm getting the following error:
In function ‘int main()’: error: cannot convert ‘__gnu_cxx::__alloc_traits<std::allocator<std::__cxx11::basic_string<char> > >::value_type {aka std::__cxx11::basic_string<char>}’ to ‘const char*’ for argument ‘1’ to ‘int sscanf(const char*, const char*, ...)’ sscanf(inputs[0], "%d %d", &n, &m); ^ error: cannot convert ‘__gnu_cxx::__alloc_traits<std::allocator<std::__cxx11::basic_string<char> > >::value_type {aka std::__cxx11::basic_string<char>}’ to ‘const char*’ for argument ‘1’ to ‘int sscanf(const char*, const char*, ...)’ sscanf(inputs[1], "%d %d %d", &x, &y, &z);
My code looks like this:
int n, m, x, y, z;
vector<string> inputs;
string read;
while (1){
getline(cin, read);
if(!read.compare("0 0"))
break;
inputs.push_back(read);
}
sscanf(inputs[0], "%d %d", &n, &m);
sscanf(inputs[1], "%d %d %d", &x, &y, &z);