You can do something like the following..
std::istringstream str;
str.rdbuf()->pubsetbuf(<buffer>,<size of buffer>);
And then use it in your getline
calls...
NOTE: getline
does not understand dos/unix difference, so the
is included in the text, which is why I chomp it!
char buffer[] = "Hello World!
This is next line
The last line";
istringstream str;
str.rdbuf()->pubsetbuf(buffer, sizeof(buffer));
string line;
while(getline(str, line))
{
// chomp the
as getline understands
if (*line.rbegin() == '
') line.erase(line.end() - 1);
cout << "line:[" << line << "]" << endl;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…