下面的代码:
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
int a = 100;
ifstream fIn;
fIn.open("test.dat");
stringstream strStream;
string str;
getline(fIn, str);
strStream << str;
strStream >> hex >> a;
fIn.close();
return 0;
}
如果没有文件test.dat时,a的值是多少呢?
a = 100,因为没有文件的时候,strStream为空,不会写入变量a中任何值。