You need to specify the append open mode like
#include <fstream>
int main() {
std::ofstream outfile;
outfile.open("test.txt", std::ios_base::app); // append instead of overwrite
outfile << "Data";
return 0;
}
More Related Contents:
- Is it possible to force c++ class instantiation on the heap?
- Can we have functions inside functions in C++?
- Detect if stdin is a terminal or pipe?
- std::unique_ptr with an incomplete type won’t compile
- C++11 thread-safe queue
- const& , & and && specifiers for member functions in C++
- Correct use of std::cout.precision() – not printing trailing zeros
- C++ convert from 1 char to string?
- Determining if a number is prime
- C#-like properties in native C++?
- Vector that can have 3 different data types C++
- Converting epoch time to “real” date/time
- copy elision: move constructor not called when using ternary expression in return statement?
- how to convert from int to char*?
- Function in C++ returns by value or by reference?
- Why can’t I create a vector of lambdas (of the same type) in C++11?
- Calculate a*a mod n without overflow
- When does cout flush?
- Why there is no placement delete expression in C++?
- Does constraint subsumption only apply to concepts?
- Why does this program crash: passing of std::string between DLLs
- Clean Eclipse Index, it is out of sync with code
- Constructor of type int
- Can’t get visual studio C++ include file ‘excpt.h’ to get installed
- Convexity defects C++ OpenCv
- Explicitly initialize DWORD to 1, but debugger shows wildly out of range value
- Struct inheritance in C++
- Concatenating strings doesn’t work as expected [closed]
- How to typedef a template class? [duplicate]
- How to ignore false positive memory leaks from _CrtDumpMemoryLeaks?