c++ files
// basic file operations
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}
c++ files
// basic file operations
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}
how to handle files with c++
#include <iostream>
#include <fstream>
#include <windows.h>
using namespace std;
int main () {
//write
ofstream writer("file.txt");
string test = " /nTest2";
writer << "Test text";
writer << test;
writer.close();
//read
ifstream reader("file.txt");
string getter
while (getline(reader, getter))
{
dataAdderInp >> getter;
}
cout << getter;
// add a new text to an exist file and keep the text that is in it.
ofstream add("file.txt", std::ios::out | std::ios::app);
add << "/n bonus text";
add.close();
return 0;
}
//if you run this you will get:
// -a file with: "Text text /n Test2"
// -and a console output: "Text text /n Test2"
// -and in the end your file will get a text, so it will looks like: "Text text /n Test2 /n bonus text"
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