在c ++中向/从文件读取写入变量

时间:2017-08-20 12:02:55

标签: c++ file save

我正在尝试让我的c ++程序写入然后从文件中读取变量,但没有成功..这是代码:

#include <iostream>
#include <fstream>
using namespace std;
int f;
int main()

{
    ifstream in("variabila.txt");


  ofstream fout;
fout.open("variabila.txt");

fout<<f<<endl;
fout.close();

cout << f << endl;
cin >> f;
in >> f;
 cout << f << endl;

return 0;
}
你能帮帮我吗?

1 个答案:

答案 0 :(得分:0)

关闭文件后,您应该打开文件进行阅读。

false