Since you're attempting to parse input from a file stream, and you're dealing with possibility of multiple words, if you wish to do so with generic support and one that is fully customizable - i.e. you want to parse any type of input, then you would require Regular Expressions.
You could use C++11's regex, but that isn't supported at the moment in gcc.
So, one solution is to use the boost C++ library which should work for the standards c++98, c++03 and c++0x:
#include <string>
#include <iostream>
#include <cstdlib>
#include <boost/regex.hpp>
using namespace std;
int main() {
string text = "hss cscf \"serving\" 32.5 ims 112.134";
boost::regex e("(\\w+)\\s(\\w+)\\s\"(\\w+\\s?)+\"\\s([0-9]+(\\.[0-9][0-9]?)?)\\s(\\w+)\\s([0-9]+(\\.[0-9][0-9]?)?)");
boost::sregex_token_iterator iter(text.begin(), text.end(), e, 0);
boost::sregex_token_iterator end;
for(; iter != end; ++iter) {
std::cout << *iter << std::endl;
}
return 0;
}
You can compile it using gcc (I used gcc-4.7.2) via the following:
g++ {filename} -std={language version} -I{your boost install location} -L{your boost library location} -o {output filename} {your boost library location}/libboost_regex.a
As for why the horridly long regex, if you wish to support full decimal parsing using a regex, then the above will work correctly for the following strings:
"hss cscf \"serving\" 32.5 ims 112.134"
"hss cscf \"serving more than one\" 32.5 ims 112.134"
"hss cscf \"serving\" 32 ims 112"
References:
Boost Regex: http://www.solarix.ru/for_developers/api/regex-en.html