ofstream:- 尽管正在创建文件,但文本文件上没有输出
ofstream:- no output on the text file though the file is getting created
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()
即可看到内容。
顺便说一句,当你关闭程序时,流也会在销毁期间被刷新,所以你也会看到内容。
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()
即可看到内容。
顺便说一句,当你关闭程序时,流也会在销毁期间被刷新,所以你也会看到内容。