【发布时间】:2015-11-06 20:32:17
【问题描述】:
我使用的是simple file-slurp,我决定添加一些错误检查。我很惊讶一个空文件会出错。每个空序列也不会发生这种情况,“”工作正常。我还验证了 rdbuf() 正在返回一个非空指针。
#include <iostream>
#include <sstream>
using namespace std;
int main(int, char**){
istringstream in(""); // Succeeds if non-empty
stringstream sstr;
if (sstr << in.rdbuf()) { // Succeeds if I replace in.rdbuf() with ""
cout << "Read Successful\n";
}else{
cout << "Read Failed\n";
}
}
【问题讨论】: