how to handle files with c 2b 2b

Solutions on MaxInterview for how to handle files with c 2b 2b by the best coders in the world

showing results for - "how to handle files with c 2b 2b"
Dianna
08 May 2018
1#include <iostream>
2#include <fstream>
3#include <windows.h>
4using namespace std;
5
6int main () {
7  //write
8  ofstream writer("file.txt");
9  string test = " /nTest2";
10  writer << "Test text";
11  writer << test;
12  writer.close();
13  
14  //read
15  ifstream reader("file.txt");
16  string getter
17  while (getline(reader, getter))
18			{
19				dataAdderInp >> getter;
20			}
21  
22  cout << getter;
23  // add a new text to an exist file and keep the text that is in it.
24  ofstream add("file.txt", std::ios::out | std::ios::app);
25  add << "/n bonus text";
26  add.close();
27  return 0;
28}
29//if you run this you will get:
30// -a file with: "Text text /n Test2"
31// -and a console output: "Text text /n Test2"
32// -and in the end your file will get a text, so it will looks like: "Text text /n Test2 /n bonus text"