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 intege开发者_运维百科rs from that. Is there any way to avoid those nasty dummy variables?
Thanks in advance and have a nice day!
sstr.ignore(128,' ');
Ignore until next space, or until 128 characters were read.
You can get by with a single dummy (per type):
std::string str("111 222.2 333 444.4 555");
std::stringstream sstr(str);
int i, j, k;
float dummy;
sstr >> i >> dummy >> j >> dummy >> k;
精彩评论