Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore values from stringstream (like %*f in sscanf)

I'm trying to get rid of old unsafe C functions, including sscanf(). Right now I'm using

#include <sstream>
std::string str = "111 222.2 333 444.4 555";
std::stringstream sstr(str);
int i, j, k;
float dummy1, dummy2;
sstr >> i >> dummy1 >> j >> dummy2 >> k;  

I just need the integers from that. Is there any way to avoid those nasty dummy variables?

Thanks in advance and have a nice day!

like image 846
Gunnar Avatar asked Nov 24 '10 12:11

Gunnar


1 Answers

sstr.ignore(128,' ');

Ignore until next space, or until 128 characters were read.

like image 129
Šimon Tóth Avatar answered Oct 31 '22 18:10

Šimon Tóth