I have a class to hold configuration data. Each item has a key and
associated value, both strings. The key is in the form
"foo::bar::name::space", and the key will be stored in a tree like
this (each level is an instance of the class with a vector holding
`-space = value
To look up a value, (string val =
config.lookup("foo::bar::name::space")), I need to split up
"foo::bar::name::space" into "foo" and "bar::name::space". Once foo
is found, the function recurses until no tokens are left, and then the
value is returned. If the key is invalid, an exception is thrown.
What is the "C++ way" to separate the tokens? Coming from C, I can
think of plenty of ways to do it, but there must be a clean and simple
way. From what I've read, istringstreams are a nice approach, but I'm
not sure how to pull out only to the delimiter, discard the delimiter
and so on.
Alternatively, string::find("::") can tell me where the first
delimiter is, and then I can use string::substr to split it up. It's
not clear what's returned if delim isn't found, though (WTH is
npos??), or how it's different to find_first_of().
Could anyone recommend a good guide (either book or on-line) to
libstdc++ and the STL? The SGI STL guide doesn't go into much depth,
nd doesn't document all the standard library, and the GCC doxygen docs
are quite incomplete (my libstdc++5 docs no longer mention
std::basic_string, and the libstdc++3 version has no descriptions).
I've got a couple of books, but they only describe the language, and
don't go into iostreams, streambufs, strings, STL etc.
Printing on GNU/Linux? http://gimp-print.sourceforge.net/
GPG Public Key: 0x25BFB848 available on public keyservers