add some filemanipulation

This commit is contained in:
lucaspalomodevelop 2022-11-02 18:57:34 +01:00
parent e21d1337e0
commit 7608773cab
3 changed files with 43 additions and 2 deletions

View File

@ -1,6 +1,43 @@
#include <iostream>
#include <fstream>
#include <string>
int main() {
std::cout << "Hello World!"<< std::endl;
using namespace std;
void readfile(string file);
void writefile(string file);
int main()
{
writefile("./testfile.txt");
readfile("./testfile.txt");
return 0;
}
void readfile(string file)
{
string line;
ifstream myfile;
myfile.open(file);
if (myfile.is_open())
{
while (getline(myfile, line))
{
cout << line << '\n';
}
myfile.close();
}
}
void writefile(string file)
{
string line;
ofstream myfile;
myfile.open(file,std::ios_base::app);
if (myfile.is_open())
{
myfile << "hallo\n";
}
myfile.close();
}

Binary file not shown.

4
cpp_1/testfile.txt Normal file
View File

@ -0,0 +1,4 @@
hallo
hallo
hallo
hallo