开发者

iostream - reading string with embedded blanks

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 >> t开发者_Go百科ag >> ws >> ???? >> sentence;

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


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);


If there will be no line breaks,

iss >> i >> tag;
getline(iss, sentence);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜