You should add fstream::out to open method like this:
file.open("test.txt",fstream::out);
More information about fstream flags, check out this link: http://www.cplusplus.com/reference/fstream/fstream/open/
More Related Contents:
- mmap() vs. reading blocks
- Getting a FILE* from a std::fstream
- How to count lines of a file in C++?
- How to shift characters to ASCII values in a file based on user input c++ [closed]
- c++ open file in one line
- How do I take values from text file and input into a 2D array? c++
- Read file line by line using ifstream in C++
- Read whole ASCII file into C++ std::string [duplicate]
- How do I read an entire file into a std::string in C++?
- Reading from text file until EOF repeats last line [duplicate]
- Copy a file in a sane, safe and efficient way
- How to construct a c++ fstream from a POSIX file descriptor?
- Difference between files written in binary and text mode
- How to write a large buffer into a binary file in C++, fast?
- How do I make my program watch for file modification in C++?
- Read file-contents into a string in C++ [duplicate]
- Using C++ filestreams (fstream), how can you determine the size of a file?
- C++ Filehandling: Difference between ios::app and ios::ate?
- Why don’t the std::fstream classes take a std::string?
- How to signify no more input for string ss in the loop while (cin >> ss)
- checking for eof in string::getline
- C++ ifstream failbit and badbit
- Intercept windows open file
- Reading and writing to the same file using the same fstream
- What’s the difference between opening a file with ios::binary or ios::out or both?
- std::ofstream, check if file exists before writing
- CLion C++ can’t read/open .txt file in project directory
- Why can’t I move std::ofstream?
- Reading files larger than 4GB using c++ stl
- Performance Difference Between C and C++ Style File IO