.


:




:

































 

 

 

 


6.1.




 

#include <iostream>

#include <iomanip>

#include <fstream>

#include <string>

 

using namespace std;

 

int main (void)

{

// file.txt;

ofstream fout("file.txt");

int ival;

cout << "enter integer value: ";

cin >> ival;

fout << setw(10) << setfill('0') << showpos << internal << ival << endl;

 

double dval;

cout << "enter double value: ";

cin >> dval;

fout << fixed << dval << endl;

 

string str;

cout << "enter string: ";

cin >> str;

fout << str << endl;

 

return 0;

}

 

6.2. .

 

#include <iostream>

#include <fstream>

#include <string>

 

using namespace std;

 

int main (void)

{

// file.txt;

ifstream fin("file.txt");

 

int ival;

double dval;

string str;

fin >> ival >> dval >> str;

 

cout << ival << endl << dval << endl << str << endl;

 

return 0;

}

 

6.2.

, .

6.1. ifstream.

gcount ,
get
ignore ,
peek
putback
read
seekg
tellg
eof
open ,
close ,

6.2. ofstream.

flush
put
seekp
tellp
write
open ,
close ,

 

6.3. .

 

#include <iostream>

#include <fstream>

#include <string>

 

using namespace std;

 

int main (void)

{

string buf;

 

// file.txt;

ofstream fout("file.txt");

// ;

getline(cin, buf);

 

// file.txt;

fout << buf;

// , ;

fout.close();

 

// file.txt;

ifstream fin("file.txt");

// file.txt ;

while (!fin.eof())

cout << static_cast<char>(fin.get());

cout << endl;

// , ;

fin.close();

return 0;

}

 

6.3.

, . , .

6.3. .

badbit
eofbit
failbit
goodbit
hardfail

6.4. .

eof eof
fail badbit failbit, hardfail
bad badbit hardfail
good goodbit
clear

 

6.4.

, , , . , . , , .

6.5. .

in ( ifsteream)
out ( ofsteream)
ate
app
trunc ,
nocreate ,
noreplace ate app
binary

 





:


: 2016-09-06; !; : 413 |


:

:

.
==> ...

1215 - | 1186 -


© 2015-2024 lektsii.org - -

: 0.01 .