我需要将一个 int 序列化为本地文件并将其读入内存。这是代码
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
int _tmain ( int argc, _TCHAR* argv[] )
{
ofstream fileout;
fileout.open ( "data,txt" );
fileout << 99999999;
fileout << 1;
cout << fileout.tellp() << endl;
fileout.flush();
fileout.close();
ifstream fileint;
fileint.open ( "data,txt" );
int i, a;
fileint >> i >> a; //i != 99999999 a!= 1 WHY?
cout << fileint.tellg() << endl;
return 0;
}
但它不能正常工作,我无法得到 i==99999999 或 a==1。那有什么问题?