write to file in C++
ofstream myfile;
myfile.open("file.txt");
myfile << "write this to file"
write to file in C++
ofstream myfile;
myfile.open("file.txt");
myfile << "write this to file"
write to file in c++
++ cCopy#include <iostream>
#include <fstream>
using std::cout; using std::ofstream;
using std::endl; using std::string;
using std::fstream;
int main()
{
string filename("tmp.txt");
fstream file_out;
file_out.open(filename, std::ios_base::out);
if (!file_out.is_open()) {
cout << "failed to open " << filename << '\n';
} else {
file_out << "Some random text to write." << endl;
cout << "Done Writing!" << endl;
}
return EXIT_SUCCESS;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us