问题标题: 存档代码

3
2
已解决
廖睿轩
廖睿轩
新手光能
新手光能

有了他,**再也不用担心我不会存档了!

#include<iostream>
#include<fstream>
#include<windows.h>
using namespace std;
int main()
{
    ifstream in;

    in.open("读入文件.txt");
    if(in.fail())
    {
        cout<<"请将读入文件与此文件放在同一个路径。";
        exit(1);
    }//这一段可以改为 exit(in.fail());

    int i;
    Sleep(1000);//等待1秒。
    cout<<"上次,你输入的值是";
    in>>i;
    cout<<i;
    in.close();

    Sleep(2000);
    system("cls");//清屏。

    ofstream out;
    out.open("读出文件.txt");
    if(out.fail())
    {
        cout<<"请将读出文件与此文件放在同一个路径。";
        exit(1);
    }
    cout<<"输入一个数:";
    cin>>i;
    out<<i;
    out.close();

    out.open("测试1 (1).txt");
    out<<i;
    out.close();
    cout<<"已将此值存放。";

    return 0;
}

 


0
已采纳
王文博
王文博
缔造者之神
缔造者之神

**=?

freopen哪里去了?

0
冮欢
冮欢
资深守护
资深守护

是啊,有freopen为什么要用这个?

0
0
0
我要回答