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"
我想在注册新用户时在文件末尾添加新字符串,它会覆盖以前的值。
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(;
相关文章:
- 这对"With a stackless coroutine, only the top-level routine may be suspended."意味着什么
- 为什么我会" void value not ignored as it ought to be"?
- Doees the 'this' 指针参与虚函数的多态行为
- 为什么当我为 for(auto& it : myUnorderedMap) {... = std::move(it.second)} 时,我会得到一个 const 引用?
- 为什么我会收到"Run-Time Check Failure #2 - Stack around the variable 'pr' was corrupted"错误?
- 您将如何连接"on the fly"文本+整数并将其传递给函数?
- Is it good to use SDL_PIXELFORMAT_UNKNOWN?
- 如何理解"Temporary objs are destroyed as the last step in evaluating the full-expression"?谁能用一些简单的例子来说明这
- 如何解决C++中声纳库贝静态代码分析错误"Explicitly define the missing copy constructor, move constructor .."
- Configuring the MPEG4MediaSink
- 这在C++ "It does not own the underlying data, and so is cheap to copy or assign"中意味着什么
- What is the std::chrono::time_point equivalent of std::numer
- 如何在数据库程序中添加"reduce the quantity of an item"功能?
- "already has the suffix -ipad. Using it."找不到 Cocos2d-x 图像
- C++ " I want to add a new string at the end of the file How Can I do it? please help"中的文件处理
- 优化"It's the Great Pumpkin Patch." ACM 1999 实践
- Could it be the case that sizeof(T*) != sizeof(const T*)?
- 无法在另一台计算机上运行我的 exe 文件。 "Application requested the runtime to terminate it in an unusual way"错误
- [conv]/6 中"The expression e is used as a glvalue if and only if the initialization uses it as a glva
- c++ 服务正在停止,出现错误"this application has requested the runtime to terminate it an unusual way"