mirror of
https://github.com/lucaspalomodevelop/cpp_stuff.git
synced 2026-03-12 22:47:22 +00:00
add some filemanipulation
This commit is contained in:
parent
e21d1337e0
commit
7608773cab
@ -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();
|
||||
}
|
||||
BIN
cpp_1/program
BIN
cpp_1/program
Binary file not shown.
4
cpp_1/testfile.txt
Normal file
4
cpp_1/testfile.txt
Normal file
@ -0,0 +1,4 @@
|
||||
hallo
|
||||
hallo
|
||||
hallo
|
||||
hallo
|
||||
Loading…
x
Reference in New Issue
Block a user