c++ 读写文件出错
feel8 2006-12-22 04:47:48 判断一个文件存在不存在?
如果不存在,写进一个数字1
如果存在,读出数字,加一后再存入,直到读出的数字为100,执行test()函数。
下面的代码可以写1进去,但是读出后就变成一串数字?
#include "iostream.h"
#include "fstream.h"
using namespace std;
#define NUM_FILE "D:\\test.txt"
int main()
{
int i;
ifstream r_file(NUM_FILE, ios::binary);
if(!r_file)
{
r_file.close();
ofstream w_file(NUM_FILE, ios::binary);
w_file << 1;
w_file.close();
}
else
{
cout << r_file.get();
i << r_file.get();
cout << i;
}
system("pause");
return(0);
}