0
I just started studying c++ and I don’t 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 the sscanf
, however I am 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 is 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);
tries to use inputs[x]. c_str()
– Penachia
It worked, thank you.
– Leonardo Rodrigues