I want to write a function in C ++ to replace C sscanf, which assigns matches to an iterator.
Basically, I need something like:
string s = "0.5 6 hello"; std::vector<boost::any> any_vector; sscanv(s, "%f %i %s", any_vector); cout << "float: " << any_cast<float>(any_vector[0]); cout << "integer: " << any_cast<integer(any_vector[1]); cout << "string: " << any_cast<string>(any_vector[2]);
The exact details may vary, but you get this idea. Any ideas for implementation?
Options so far along with problems:
- std :: istringstream : no manipulator for matching constant expressions
- Boost.Regex : not sure if this will work, and it seems a lot more complicated than necessary
- Boost.Spirit : don't think this will work for dynamically generated format strings, and it also seems more complicated than necessary
- sscanf : it will work, but it is non-standard, etc., and it will take a lot of overhead to use, since the number of arguments is determined at compile time
deuberger
source share