0
我對stringstream有一些理解問題。stringstream.good()>在VS和Eclipse編譯器中的不同行爲
例子:
stringstream stream(commands);
while (true) {
string line;
getline(stream, line);
if (!stream.good())
break;
if (line.size() > 0){
lines.push_back(line);
}
else{
break;
}
}
如果我用這個代碼在Eclipse中它是沒有問題的,它正常工作。 使用這Vistual Studio 2005中stream.good()似乎返回總是假
爲什麼呢?
我真的很感激一些解釋。
你可以拿這整個代碼,並用4行代替它,你知道... http://ideone.com/tLCTl-使用.good()幾乎從來都不是一個好主意。使用流狀態,getline返回流。 – etarion 2011-01-10 13:41:29