Skip to content

Commit 638ebf5

Browse files
authored
Update and rename getline.cpp to getline_notatnik.cpp
1 parent 0861e9e commit 638ebf5

File tree

2 files changed

+39
-20
lines changed

2 files changed

+39
-20
lines changed

getline.cpp

Lines changed: 0 additions & 20 deletions
This file was deleted.

getline_notatnik.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
int main() {
6+
char * napis = new char[128];
7+
8+
cout<<"Napiz cos: ";
9+
cin.getline(napis, 128); //zmienna i dlugosc przchwytywanych danych
10+
cout<< napis<<endl;
11+
12+
ofstream zapis;
13+
zapis.open("plik.txt", ofstream::app); //append czyli dopisywnaie nie nadpisywanie
14+
zapis<<napis<<endl;
15+
16+
zapis.close();
17+
delete [] napis;
18+
19+
20+
char * wczytane = new char[128];
21+
ifstream odczyt;
22+
odczyt.open("plik.txt");
23+
24+
if(odczyt.is_open()) {
25+
while(!odczyt.getline(wczytane, 128)) {
26+
cout<<odczyt;
27+
}
28+
odczyt.close();
29+
cout<<"Zakonczono czytanie pliku"<<endl;
30+
31+
} else {
32+
cout<<"Nie udalo sie otworzyc pliku / plik nie istnieje"<<endl;
33+
}
34+
delete[] wczytane;
35+
36+
// ^^ to wszystko mozna zrobic poprzez while(!odczyt.eof())
37+
38+
return 0;
39+
}

0 commit comments

Comments
 (0)