Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C++ by Pastew ( 13 years ago )
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main(int argc, char **argv)
{
fstream data;
data.open("plik1.txt", ios::in | ios::out | ios::binary);
if(data.good()!=true){
cout<< "Blad przy otwieraniu pliku!"<<endl;
system("pause");
return 0;
}
//strumieniem---- bez bialych znakow
string tekst;
data >> tekst;
cout<< tekst;
//getline---- cala linijka
string tekst2;
getline(data,tekst2);
cout<<tekst2;
//plik.getline(do czego zapisac,ileznakow,na_jakim_zakonczyc)
char tekst3[100];
data.getline(tekst3,100, 'd');
cout<<tekst3;
// data.read(do czego zapisac, ile znakow) gcout liczy ile bajtow, czy cos)
char bufor[100];
data.read(bufor,100);
cout<<"Wczytano bajtow do bufora: ";
cout<<data.gcount();
//--------------ZAPISYWANIE-------------------
//strumieniem
data << "Dupa :) xxx";
// data.write
char bufor2[100];
bufor2[1]='x';
bufor2[5]='q';
data.write(bufor2,6);
// ze strumienia wejscia do stringa, a pozniej stringa do pliku
string tekst4;
getline(cin,tekst4);
data.write(&tekst4;[0],tekst4.length());
//seekg() dla funkcji odczytu seekp() dla funkcji zapisu ios_base::beg ios_base::cur ios_base::end
// do konca pliku czytaj
string tekst5;
while( !data.eof() )
{
getline( data, tekst5 );
cout << tekst5 << endl;
}
//dlugosc pliku
data.seekg (0, ios::end);
unsigned dlugosc = data.tellg();
data.seekg (0, ios::beg);
data.close();
cin.get();
}
Revise this Paste