Emulate awk

I have a string like the following:

string myStr = "Monthly Ecosystem NPP = 0.360591 tDM/ha month";

How can I isolate 0.360591, as I would do in bash with a echo $myStr | awk '{ print $5 }' ?

Thanks in advance.
One way would be...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
string myStr = "Monthly Ecosystem NPP = 0.360591 tDM/ha month";
stringstream ss( myStr );
vector<string> v;
string tok;
	
while(1)
{
  ss >> tok;
  if( !ss.good() )
    break;
  v.push_back( tok );
}

string res = v.size() > 4 ? v[4] : "";
cout << res << endl;
Thank you so much...Meanwhile I've solved with the following:

1
2
3
4
5
6
7
8
string myStr = "Monthly Ecosystem NPP = 0.360591 tDM/ha month";
istringstream tokenizer(myStr);
string tok;

for(k=0; k<5; k++)
    getline(tokenizer, tok, ' ');

cout << tok << endl;
Topic archived. No new replies allowed.