I have a vector of strings "moves"

std::vector<string> moves;

and the Chars:

char fromX, toX, fromY, toY;

I use:

sscanf(moves[0], "%c%c %c%c", &fromX, &fromY, &toX, &toY);

and Compiler says:

error: no matching function for call to 'sscanf(std::string&, const char[10], char*, char*, char*, char*)'

What is the problem???

Recommended Answers

All 10 Replies

sscanf() is a C function, not c++, and knows nothing about c++ containers like std::string, you have to pass it a character array. sscanf(xx.c_str(), "%c%c %c%c", &fromX, &fromY, &toX, &toY);

Note that sscanf isn't an ordinary method or built-in function, but a very special construction in Pike.

That link is not talking about C or C++ languages.

In the code snippet you posted above, what string does xx contain? There is probably another way to do what you want without using sscanf(). Post an example of moves[0]

You are right. :S

Compiler says: has no member named 'c_str'

In the code snippet you posted above, what string does xx contain? There is probably another way to do what you want without using sscanf(). Post an example of moves[0]

Was an error. its edited in the first post.

Yes I noticed that you changed the first parameter from xx to moves[0]. So what does moves[0] contain anyway?

Yes I noticed that you changed the first parameter from xx to moves[0]. So what does moves[0] contain anyway?

contain a string

vector <string> moves;

I know that -- but post an example of the string -- such as "Hello World".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.