tags:

views:

33

answers:

2

I have a file with records that looks like this

123 Tag Now is the time for all good men to come to the aid

There always a number and some tag followed by a series of words. I want to extract the number as integer, tag as string, and sentence as string. I've done this using getline and scan plus some substring foolishness.

Is there any way to do this ala...

ispringstream iss ("123 Tag Now is the time for all good men to come to the");
integer i;
string tag, sentence;
iss >> i >> tag >> ws >> ???? >> sentence;

I.e. It would be nice if there were some way to turnoff white space as a terminator.

A: 

If there will be no line breaks,

iss >> i >> tag;
getline(iss, sentence);
KennyTM
A: 

You should be able to do it in two steps:

istringstream iss ("123 Tag Now is the time for all good men to come to the");
int i;
std::string tag, sentence;
iss >> i >> tag >> ws;
std::getline(iss, sentence);
Mark B
Well, that's certainly better than scan. I also though of retrieving the position with iss.tellg() and using a string .substr on sentence. I wonder if it could be done with a user defined manipulator?
Mike D