【发布时间】:2017-10-02 08:17:11
【问题描述】:
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 正在创建,但我输入的用户名和密码信息并未存储在该特定文本文件中
【问题讨论】:
-
何时以及如何检查文件的内容?也许您应该在检查之前
flush缓冲区? -
另外(但与您的问题无关),我建议您在显示的代码中使用 loops 而不是递归。
-
同样不相关:在
ofstream上指定ios::out毫无意义。 -
@Someprogrammerdude 我是 C++ 新手,我该如何刷新这段代码?
-
@varunkrishna 使用
ostream::flush()。例如,f.flush()。
标签: c++ string c++14 fstream ofstream