The %*s
used with sscanf
basically means to ignore a string (any characters up until a whitespace), and then after that you're telling it to read in an integer (%*s
%d
). The asterisk (*
) has nothing to do with pointers in this case.
So using stringstream
s, just emulate the same behaviour; read in a string that you can ignore before you read in the integer.
int d;
string dummy;
istringstream stream(s);
stream >> dummy >> d;
ie. With the following small program:
#include <iostream>
#include <sstream>
using namespace std;
int main(void)
{
string s = "abc 123";
int d;
string dummy;
istringstream stream(s);
stream >> dummy >> d;
cout << "The value of d is: " << d << ", and we ignored: " << dummy << endl;
return 0;
}
the output will be: The value of d is: 123, and we ignored: abc
.