Программирование >>  Расширенная версия языка c++ 

1 ... 199 200 201 [ 202 ] 203 204 205 ... 227


inv.close();

return 0;

ГЛАВА 10

Повторение пройденного

1. tinclude <iostreain>

namespace std;

fisetsci fistream)

stream, setf (ios:: scientific I ios : : uppercase) ;

return streams;

Самоучитель С++.

double f

123.23;

cout setsci f; cout

return 0;

2. Копирование файла и преобразование табуляций в пробелы ttinclude <iostream> ttinclude <fstream>

using namespace std;

in {int argc, char *argv[])

cou рование: <ввод> <вывод>\п ;

return 1;

ifstream in(argv[l]);

if(!in) {

cou << Файл ввода открыть невозможно\n ;

return



Приложение В. Ответы опросы и шения упражнений 613

ofstream out (argv [2]) ; if(lout) {

cou Файл вывода открыть невоэможноХп ; return 1;

char ch; int i= 8;

( if..

whileofO) {

in.get(ch); . -

if(ch=-Xt) for(; i>0; i -- putC ); , ..-. : else out.put(ch); if(i==-l jl ch==Xn) i = 8;

i - ;

in. close0 ; V!.-V,=t rf,--:\ .

out.close();

return 0;

3. Поиск слова в файле #include <io3tream> #include <fstream>

<cstring> using namespace

int char

if(argc!=3) {

cou Поиска йл> <слово>\п ;

return

ifstream in{argv[l]); if(!in) {

cou Файл ввода открыть невоэможноХп ;

return 1;

char

int count 0;

while ( eof (} ) { in >> str;

if ( !strcmp{str, argv[2])} count++;



614 .- Самоучитель...С++

cou [2] найден count; . n. -- =*.r

cout раз. \n ;

in.closeO;

return 0;

4. Искомой инструкцией является следующая:

. .It

out.seekp(234, ios::beg);

5. Такими функциями являются te(), good()f(), fail() и bad().

6 вывод C++ обеспечивает возможность работы с создаваемыми вами классами.

Упражнения

10.2

1. ttinclude <iostreain> using namespace std;

class I

public:

int i;

num (int x) {i = x; }

virtual void shownumO ( cout 1 \n; }

class outhex: public num { public:

outhex (int n) : num{n) {} > .i

void ShownumO ( cout << hex i \n; }

class outoct: public num I i; J-

public:

outoct (intn) : num(n) I }

void shownumO { cout oct i \n; }

int I

outoct о(10) ;

outhex h(20) ; I

o. shownumO;

h.shownum();



1 ... 199 200 201 [ 202 ] 203 204 205 ... 227

© 2006 - 2025 pmbk.ru. Генерация страницы: 0
При копировании материалов приветствуются ссылки.
Яндекс.Метрика