2012-08-24 16 views

回答

0

如果你想閱讀整個字符串:

// .str() returns a string with the contents of szBuffer 
muFunc(szBuffer.str()); 
// Once you've taken the string out, clear it 
szBuffer.str(""); 

如果要提取下一行(直到下一個\ n字符),使用istream::getline

// There are better ways to do this, but for the purposes of this 
// demonstration we'll assume the lines aren't longer than 255 bytes 
char buf[ 256 ]; 
szBuffer.getline(buf, sizeof(buf)); 
muFunc(buf); 

函數getline ()也可以使用分隔符作爲第二個參數(默認情況下爲\ n),因此您可以逐字讀取它。

相關問題