ofStream: - 尽管文件创建了,但文本文件上没有输出


    void megaadmin()
    {
        system("cls");
        cout<<"this console is only for registering new admins";
        cout<<"please enter the required username";
        string temporary_string;
        cin>>temporary_string;
        ofstream f("admin_details.txt",ios::out|ios::app);
        f<<temporary_string;
        cout<<"please enter the password";
        cin>>temporary_string;
        f<<temporary_string;
        cout<<"would u like to enter more usernames and passwords if yes enter 1 eles 2";
        int n;
        cin>>n;
        if(n==1)
            megaadmin();
        else
            exit(0);
    }

admin_details.txt正在创建,但是我输入的用户名和密码的信息没有存储在该特定的文本文件

在每个cin >> temporary_string;之后,我将添加cout << temporary_string 仅用于调试以确保字符串成功地读取。

如果是,则没有输出,因为您的流可能没有冲洗。只需致电f.flush()即可看到内容。

btw,当您关闭程序时,该流在破坏过程中也将被冲洗,因此您也会看到内容。

最新更新