C++ " I want to add a new string at the end of the file How Can I do it? please help"中的文件处理

file handling in c++ " I want to add a new string at the end of the file How Can I do it? please help"

本文关键字:the it Can please do 处理 文件 How help of add      更新时间:2023-10-16

我想在注册新用户时在文件末尾添加新字符串,它会覆盖以前的值。

write.open("usersinfo.txt");
if (write.is_open())
{
    write << username << "t" << password << "t" << cnpassword << "t" << email << "t" << number << "nn";
    cout << "nnnPlease Wait Your Data Is Saving";
    for(int i=0;i<10;i++)
    {
        cout << ".";
        Sleep(400);
    }
    cout << "nntttSign Up Successfull";
    write.close();
}

使用

write.open("usersinfo.txt", std::ios::app);
打开文件时,

写入指针已经位于末尾(即,如果要附加到文件(。

编辑

:在仔细检查标准后,第一次编辑被证明是不必要的。 std::ios::app意味着std::ios::out(27.9.1.4(。

您应该

在追加模式下打开文件,以便您可以在之前编写的内容之后添加新文本。正确的方法是write.open("usersinfo.txt", std::ios::app(;相反write.open("usersinfo.txt"(;等于write.open("usersinfo.txt", std::ios::out(;

相关文章: