gpt4 book ai didi

C++ 帮助...更新文本文件?

转载 作者:行者123 更新时间:2023-11-28 08:23:53 26 4
gpt4 key购买 nike

首先,我不太擅长c++。所以请对我放轻松。我尝试更改密码,但我只想更改文本文件中的某个密码。但是当文本文件被重写时,就像只有一个新密码存在一样。整个文件都被重写了。:(

用户.txt

admin    openmyacc
guest imguest12


void Passchange()
{
string tempass;
system("cls");
cout<<"enter current password: ";
cin>>tempass;
if(tempass==inpass)
{
cout<<"utility to change password stored in file\n";
cout<<"CHANGE PASS TO: ";
cin>>user;
ofstream Passfile("user.txt", ios::out);
Passfile<<user;
Passfile.close();
cout<<"password successfully changed";
getch();
main();
}

最佳答案

虽然追加很容易,但没有一种简单的方法可以修改文件中间的文本。您需要读取旧文件并重写它,同时检测旧条目并将其替换为新数据。

关于C++ 帮助...更新文本文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4755553/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com