Вы находитесь на странице: 1из 544

..

O+Builder 6

1
C++


2002

004.43
32.973.26-018.1
87
..

C++Builder 6. . 1. C++. -- .: , 2002 . 544 .: .

C++
C++Builder 6: , , . , ,
, , , , . Windows. 650 ,
C++, API Windows, 300 .
STL: ,
, -.
, .
: .

ISBN 5-9518-0007-2

.., 2002
, 2002

15

1. C++

17

1.1 C++
17
1.2 C++
18
1.2.1
18
1.2.2
19
1.2.3
22
1.2.4 ,
25
1.2.4.1 ,
25
1.2.4.2
27
1.2.4.3 ,

28
1.3
29
1.4
31
1.4.1 #include
31
1.4.2 #define #undef
32
1.4.2.1
32
1.4.2.2
33
1.4.2.3 #undef
36
1.4.3 :
#if, #endif, #ifdef, #ifndef, #else, #elif
36
1.4.4 #error, #line, #pragma
38
1.4.5 # ##
41
1.5
41
1.5.1
41
1.5.2
42
1.5.3 (manifest)
43
1.6
45
1.6.1
45
1.6.2
45
1.7
48
1.7.1
48
1.7.2
51
1.7.3 const
53
1.7.4
54
1.7.5
55
1.7.6 inline
57
1.7.7
57
1.7.8
59
1.8
60
1.8.1 ,
60
1.8.2 namespace using . . . 64
1.9 .
65
1.9.1
65
1.9.2
66
1.9.3

67
1.9.4 , Assign. . . . 71
1.9.5
72
1.9.6
73
1.9.7
74

C++Builder 6
1.9.8 ()
75
1.9.9 (?:)
75
1.9.10 sizeof
76
1.9.11 typeid
77
1.9.12 (&) ( * ) . . . .
77
1.9.13 (::)
77
1.9.14 : (.) (>)
77
1.9.15 () ()
78
1.9.16
81
1.9.17
82
1.10
85
1.10.1
85
1.10.1.1 if
85
1.10.1.2 switch
86
1.10.1.3 goto
87
1.10.2
88
1.10.2.1 for
88
1.10.2.2 do...while
90
1.10.2.3 while
91
1.10.2.4 : break, Continue, return, Abort . . 92
1.11
93
1.12
97
1.12.1
97
1.12.2 try ...
finally
exit
98
1.12.3 VCL
101
1.12.4 VCL Exception
106
1.12.4.1
'.
107
1.12.4.2
107
1.12.5 try ... catch
109
1.12.5.1 try ... catch
109
1.12.5.2 ,

111
1.12.6
113
1.12.6.1 throw. .
113
1.12.6.2 EAbort Abort
115
1.12.7 C++
116
1.13
119
1.14 Windows
121
1.14.1 C++Builder
121
1.14.2
122
1.14.2.1 SendMessage, PostMessage Perform
122
1.14.2.2
123
1.14.3
124
1.14.4
126

2. C++
2.1 ,
2.2
2.3
2.4
2.5
2.5.1
2.5.2 AnsiString
2.6
2.7
2.8
2.8.1

129
129
132
134
136
137
137
140
143
144
147
. 147


2.8.2
149
2.8.3
151
2.9
^ 154
2.10
154
2.10.1 /
154
2.10.2 /
156
2.10.2.1
156
2.10.2.2
156
2.10.2.3
160
2.10.2.4 /,
163
2.10.3 / C++
165
2.10.3.1
165
2.10.3.2
169
2.10.3.3
172
2.11
174
2.11.1
174
2.11.2
176
2.11.3 ,
177
2.12
179
2.12.1
179
2.12.2
180
2.12.3 C++
182
2.12.4
183
2.13
184
2.14
185
2.14.1
185
2.14.2 -, ,

. 188
2.14.3 -, , . . . . 190
2.14.4
191
2.14.5
194
2.14.6 , ,

196
2.14.7 ,
C++Builder
200
2.14.7.1
200
2.14.7.2
203
2.14.8
204

3. , C++, C++Builder, API Windows . . 207


3.1
3.1.1
3.1.2
3.1.3 ,
3.1.3.1
3.1.3.2
3.1.3.3 Format
3.1.3.4 TFloatFormat TFloatValue

3.1.3.5 FormatFloat
3.1.4 ,
3.1.4.1 _doserrno, errho _sys_nerr ,

3.1.4.2
3.1.4.3 EDOM, ERANGE
3.1.4.4 _matherr _matherrl
3.1.5 Windows
WM_ACTIVATE
WM ACTIVATEAPP

207
207
211
212
212
216
217
220
221
223
223
223
225
*
227
227
227

O+Builder 6
WM_CANCELMODE
.228
WM_CLOSE
228
WM_GETMINMAXINFO
228
WM_GETTEXT
229
WM_SETFONT
230
WM_SETTEXT
230
3.1.6 AnsiString
231
3.1.7 TDateTime
235
3.1.8 TStringFloatFormat -
236
3.2
237
3.2.1 ,
237
3.2.2
238
3.2.3
241
3.2.4
243
3.2.5
244
3.2.6 FPU
246
3.3
247
3.3.1
247
3.3.1.1 char *
247
3.3.1.2 ,
SysUtils.hpp
249
3.3.2 . :
252
3.3.3
261
3.4
262
3.4.1
262
3.4.2
264
3.4.2.1
264
3.4.2.2
265
3.4.2.3 AnsiString
272
3.5
275
3.5.1 ,
275
3.5.2 , FILE . . . 277
3.5.3 , . . . . 281
3.5.4 /
284
3.5.5
290
3.5.6
293
3.6
302
3.6.1
302
3.6.2
304
3.6.3
306
3.7
307
3.7.1
307
3.7.2
311
3.7.3
314
3.7.4 C++ C++Builder
317
3.7.5 API Windows
322
3.8 Windows
323

4.

abort
Abort
abs
AnsiCompareStr
AnsiCompareText
AnsiLowerCase
AnsiPos
AnsiStrComp
AnsiStrlComp
AnsiStrLower
AnsiStrPos
AnsiStrUpper

325

325
325
326
326
327
327
328
329
330
331
331
331


AnsiToOem DOS
AnsiUpperCase
assert
Bounds
calloc
ceil
Ceil
ceill
cgets
CharToOem, CharToOemBuff DOS
_clear87 FPU
_clearfp FPU
CompareDate
CompareDateTime
CompareText
CompareTime
Compare Value
_contro!87 FPU
_controlfp FPU
cprintf
cputs
CreateMessageDialog
CreateProcess
_crotl
_crotr
cscanf
cwait
Date
DateTimeToStr
DateTimeToString

DateToStr
DayOf
DayOfTheMonth
DayOfTheWeek
DayOfWeek
DaysBetween
DaySpan
DecodeDate TDateTime
DecodeDateTime TDateTime
DecodeTirae TDateTime
div
DivMod
EncodeDate TDateTime
EncodeDateTlme TDateTime
EncodeTime TDateTime
EnsureRange ,
exec...
fabs, fabsl
f getc /
_fgetchar
fgets
'.
fgetwc
_fgetwchar
fgetws
FindClose
FindExecutable API Windows
findfirst
FindFirst C++Builder
FindNext
FloatToStr
FloatToStrF
floor, Floor, floorl
fmod, fmodl
Format
FormatDateTime
fprintf
f putc
_fputchar
fputs /
f putwc
,
_fputwchar
fputws
free
frexp, frexpl, Frexp
fscanf

9
331
331
332
332
334
334
334
334
334
335
336
337
337
338
338
338
338
339
341
341
341
341
341
348
348
349
349
350
351
351
353
354
355
355
355
355
356
356
357
357
357
358
358
360
360
360
360
363
363
367
367
367
367
367
367
367
368
370
373
374
374
375
375
376
377
377
380
380
380
382
382
382
382
, . . . 382
383

10

C++Builder
fwprintf
fwscanf
get - ifstream
Get8087CW FPU
getc
getch
getchar
getche
GetExceptionMask
getline - ifstream
GetLastError API Windows
GetNextWindow API Windows
GetPrecisionMode
GetRoundMode
gets
getwc
getwchar
GetWindow API Windows
GetWindowText API Windows
_getws
HourOf
HourOfTheDay
HoursBetween
HourSpan
InputBox
InputQuery
InRange
IntPower
IntToStr
Islnfinite
IsNan
IsToday ,
labs
Idexp, Idexpl, Ldexp 2
Idiv
LnXPl
log
loglO, loglOl, logl
LoglO, Log2, LogN
LowerCase
_lrand
_lrotl
_lrotr
main
malloc . . .
MaxlntValue, MaxValue
_mbscpy
_mbslwr
_mbsncpy
_mbsupr
Mean
MeanAndStdDev

memccpy
memcpy .'
memmove
memset
MessageBox TApplication
MessageDlg
MessageDlgPos
MilliSecondOf
MilliSecondOfTheSecond
MilliSecondsBetween
MilliSecondSpan
MinlntValue, MinValue
MinuteOf
MinuteOfTheHour
MinutesBetween
MinuteSpan
MomentSkewKurtosis
MonthOf
MonthOfTheYear
MonthsBetween
MonthSpan
_new_handler
Norm

383
383
383
385
385
385
385
385
385
387
388
388
389
389
390
390
390
390
391
392
392
392
392
393
393
394
394
395
395
395
396
396
396
396
397
397
' . . . . . 397
397
397
398
398
398
398
398
400
401
402
402
402
402
402
402
403
403
404
405
405
407
411
411
411
412
412
412
412
413
413
413
413
414
414
414
415
415
415

11

Now
415
OemToChar, OemToCharBuff DOS
415
Point
416
poly, polyl, Poly
417
PopnStdDev
418
PopnVariance
418
PostMessage API Windows
419
pow, powl
420
powlO, powlOl
420
Power
420
printf
420
putc
420
putchar
420
puts
421
putwc
421
putwchar
421
_putws
421
raise
421
rand, randomize, Randomize, RandG
421
random
421
realloc
423
Rect
423
RegisterWindowMessage API Windows
423
_rotl
423
_rotr
424
RoundTo
424
Same Value
425
scanf
425
SecondOf
428
SecondOfTheMinute
428
SecondsBetween
429
SecondSpan
429
SelectDirectory
429
SendMessage API Windows
432
set_new_handler
433
Set8087CW FPU
434
SetExceptionMask .
434
SetPrecisionMode
434
SetRoundMode
434
ShellExecute API Windows
435
SHGetFilelnfo
437
ShowMessage
440
ShowMessageFmt
441
ShowMessagePos
441
Sign
441
signal
442
SimpleRoundTo
444
Sleep
444
SmallPoint
445
spawn...
445
sprintf
. 450
srand
450
sscanf
450
_status87 FPU
450
_statusfp FPU
451
StdDev
451
StrCopy
451
strcpy
453
StrECopy
453
StrLCopy
453
StrLower
453
strlwr
45,3
StrMove
'
453
strncpy
453
StrPos
453
StrToCurr, StrToInt, StrToFloat . . . . 453
StrToDate
454
StrToDateDef
456
StrToDateTime
456
StrToDateTimeDef
456
StrToTime
456
StrToTimeDef
456
Strtlpper
456
strupr
456
Sumlnt Sum
456
SumOfSquares
457

12

C++Builder 6
SumsAndSquares
swprintf
swscanf
system
Time
TimeToStr
_tmain main
Today
Tomorrow
TotalVariance
TryEncodeDate TDateTime
TryEncodeDateTime TDateTime
TryEncodeTime TDateTime
_tWinMain
ungetc
ungetch
ungetwc
Uppercase
va_start, va_arg, va_end
Variance
vfprintf
vfscanf
vfwprintf
vprintf
vscanf
vsprintf
vsscanf
vswprintf
vwprintf
wait
wcscpy
wcsncpy
_wcslwr
_wcsupr
_wexec...
_wfindfirst
_wfindnext
WinExec API Windows
WinMain
wmain
_wmemcpy
_wmemset
wprintf
wscanf
_wspavn...
_wsystem
wWinMain
YearOf
YearsBetween
YearSpan
Yesterday

5. STL
5.1 STL?
5.2 STL C++Builder
5.3 STL
5.4
5.4.1
5.4.2
5.4.3
5.4.4
5.4.5
5.4.6
5.4.6.1
5.4.6.2 multiset set
5.4.6.3 multimap
5.5
5.5.1
5.5.2
5.5.3

457
458
458
458
458
458
458
459
459
459
459
459
459
459
460
460
460
460
460
461
462
462
462
462
462
462
462
462
462
462
462
463
463
463
463
463
463
463
466
466
466
467
467
467
467
467
467
467
467
468
468

469
469
469
470
472
472
474
477
482
486
490
490
491
494
495
495
499
. 501

13

5.5.4 ,
504
5.6 string
505
5.7
509
5.7.1
509
5.7.2
510
5.7.3
510
5.7.4 . . . 513
5.7.5
514
5.7.6
516
5.7.7
516
5.7.8
519
5.7.9
520
5.7.10
521
5.7.11
524
5.7.12 '(heap)
526
5.7.13
527
5.7.14
528
5.8 -
529


C++ C++Builder 6

533
541


, ? . , C++. .
,
, ,
, . . , , , .
. , -, , , ,
C++, .
, , :
, ,
, , . ,
,
. C++ ++ilder,
. STL
. .

. -, ,
, ,
C++. , ,
.
[3] [4] C++
C++Builder 6. -,
[2], C++
C++Builder 6. , , .
, . , . . ,
. (. [2]).
, . , ,
. , .
, C++Builder 6
[1], , , .
[1] C++ . , C++, , , ,
Windows,
, . , C++
, [1] .

16

C++Builder

C++ API
Windows. (
), , ( 300).
5,
C++. [1] .
, C++ [1],
2/3 ,
. ,
.

1

C++

C++, C++Builder. , , C++Builder, , C++. , , Object Pascal. ,
, , C++Builder. ,
,
- C++.
, STL C++. , , C++ , , ,
.., . 5.

1.1 C++
C++
. ,
, C++ .
, ,
C++. C++ , , , , , .
, , C++ . . 2 . 2.14. ,
, , , . 2.14.8 1.7.8.
. 1.9.17. . 1.12.
C++, .
C++
:
. , , DATABASE, DataBase, Database database
, . , ,
_". . ,
.
(, , , ) , .

18

/* */.
, ,
, .
. , ,
"*/". , C++Builder 6 . Nested
Comments Advanced Compiler .
, .
.
"//" ,
, . , "//" .
";". .
.
. , , , , , , .
, .
{ } . , , .
, , , .
.

1.2 C++
1.2.1
C++ (, , ,
, ) . main ( WIN32) WinMain Windows. . C++Builder
, .
-
.
, . .
- ,
.
C++Builder .
, , C++Builder
. . , . , ,
. .
.

C++

19


, , ,
.., , .
.. .h.
, (). .
, . , .
,
.
.
() .
. , .obj.
, ,
.. .

1.2.2
C++Builder , . ,
Windows, WinMain. , main.
, . . , ,
. - , +- l-Builder. ,
, - , .
, C++Builder Project | V i e w Source.
Windows ( ):
//
__________________________________________
^ __________ ______
//
#include <vcl.h>
#pragma hdrstop
// , ^
USERES ( " P r o j e c t l . r e s " ) ;
USEFORM("Unitl.cpp", Forml);
USEFORM("Onit2.cpp", F o r m 2 ) ;
/
/
__________________________________________________________
// main
WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int)
try

Application->Initialize () ;
Application->CreateForm( _ classid (TForml) , SForml)

20

1
Application->CreateForm(
Application->Run();

classid(TForm2) , &Form2);

}
catch (Exception Sexception)
{
Application->ShowException(.exception);
}
return 0;

, "#".
(.
. 1.4). #include. . , . , #include <vcl.h> vcl.h, , C++Builder.
USERES
USEFORM. ,
, . .
USEFORM, . C+4-Builder USEFORM , .
, (,
"Unitl.cpp"), .

- - WinMain.
. , Windows
. API Windows (API Windows Windows, ). WinMain - -
( ). , , .

WinExec. . ShowWindow.
WinMain . 4. main, . , . , WinMain, main .
WinMain ,
. Application>Initialize
. Application>CreateForm .
, .
.
Application>Run
. , .
WinMain try, catch. , -

C++

21

, . , ,
catch. Application>ShowException.
. 1.12.
WinMain return(O),
0.

. , USEFORM Application>CreateForm,
. .
- , , , , , . , - (, ). - . , .
, ,
extern (. . 1.6.2). , ,
, (. . 1.8).
, . , , , Form2
, Y. WinMain
:
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR S, int)

S, .
Application->CreateForm(

classid(TForm2), &Form2);


if

(S[OJ

'Y')

Application->CreateForm(

classid(TForm2), &Form2);

, Projectl
Projectl Y, Form2 .
.
, , .
( MessageBox . . 9):
if (Application->MessageBox(.
" ?",
" ",
MB_YESNOCANCEL + MB_ICONQUESTION) == I D Y E S )
Application->CreateForm( c l a s s i d ( T F o r m 2 ) , S F o r m 2 ) ;

, . 1.1. ,
.

22

. 1.1

,.4 .

, , ,
.. , , .
, . , - , , C++Builder File | New Unit.
, . , , , - , , .
, , , begin, ,
. Unitl.cpp,
Unitl.h (
. . 1.2.3).
#include " U n i t l . h "
Unitl.h, WinMain
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR S,

int)

.. S, ,
WinMain :
begin(S);

begin .
begin :
void b e g i n ( S t r i n g s)
{

//
}

, ,
, .
: Projectl,
Project2 .. .
. .
WinMain, Windows. main, , . . 4.

1.2.3
, . : , ,
. , -^
( TLabel) (

C++

23

TButton). ,
.
:
//
tfifndef UnitlH
#define UnitlH
//
#include Classes.hpp>
#include <Controls.hpp>
tinclude <StdCtrls.hpp>
#include <Forms.hpp>
//
// ( , include),
//

//
// TForml
class TForml : public TForm
{
published:
// IDE-managed Components
//
TButton *Buttonl;
TLabel *Labell;
void
fastcall ButtonlClick(TObject *Sender);
private:
// User declarations
//
// , , ,
// ,
public:
// User declarations
//
// , , ,
//
fastcall TForml(TComponent* Owner);

};
//

extern PACKAGE TForml *Forml;


//
,
// , , ,
// ;
//
//
#endif

:
//
finclude <vcl.h>
#pragma hdrstop
#include "Unitl.h"
//
tpragma package(smart_init)
tpragma resource "*.dm"
//
// ( , include),
//
// Forml
TForml *Forml;
//

24

// Forml
fastcall TForml::TForml(TComponent* Owner)
: TForm(Owner)
^, {
// ,
//
}
//
// ,
//
// ;
// ,
// ,
// ,
void
fastcall TForml::ButtonlClick(TObject *Sender)
(
Close () ;
}

. . , C++Builder
include (. . 1.4), ,
, , , ,
. .
include .
.
TForml. :
published
, , private , public
.
published : Buttonl TButton
Labell TLabel. ButtonlClick Buttonl. ,
published, C++Builder . , , . private public , , . , C++Builder public, . , private, . ,
, C++Builder public, () TForml.
PACKAGE, .
, , ,
(. . 1.8)
, .
.

Forml, . ,
- . . - .
, . ,

C++

25

, , , , .
C++Builder :
"Unitl", "Unit2" ..

1.2.4 ,
1.2.4.1 ,
, , . , : Buttonl TButton Labell TLabel.
, , , , , .
:
//
#ifndef UnitlH
tfdefine UnitlH
//
,
.
#include <Classes.hpp>
tinclude <Controls.hpp>
tinclude <StdCtrls.hpp>
tinclude <Forms.hpp>
//
class TForml : public TForm
{
published:
// IDE-managed Components
TLabel *Labell;
TButton *Buttonl;
void
fastcall ButtonlClick(TObject *Sender);
private:
// User declarations
// Fl Ch6
void
fastcall Fl(char Ch);
char Ch6;
public:
// User declarations
fastcall TForml(TComponent* Owner);
// Chi F2
// ,
//
char Chi;
void
fastcall F2(char Ch);
};
//
extern PACKAGE TForml *Forml;
// Ch2 F3
// ; Ch2 ,
// extern;
// F3 ,
//
char Ch2;
void F3(char Ch);
tendif

:
//
tinclude <vcl.h>

26

1
tpragma hdrstop
#include "Unitl.h"
//
tpragma package(smart_init)
#pragma resource "*.dfm"
TForml *Forml;
//

fastcall TForml::TForml(TComponent* Owner)


: TForm(Owner)

{
}
//
// Ch3 F4
// ; ,
// extern;
// F4 ,
//
char Ch3;
void F4(char Ch)
f
Forml->Labell->Caption = Forml->Labell->Caption + Ch +
Forml->Chl;
)
//
.
,
void
fastcall TForml::Fl(char Ch)
{
Labell->Caption = Labell->Caption + Ch + Chi;
}
//
void
f a s t c a l l T F o r m l : : F 2 ( c h a r Ch)
{

Labell->Caption = Labell->Caption + Ch + Chi;


)
//

void F3(char Ch)


(
Forml->Labell->Caption = Forml->Labell->Caption + Ch +
Forml->Chl;
}
//
void
fastcall TForml::ButtonlClick(TObject *Sender)
{
// Ch4
char Ch4;
Chi
Ch2
Ch3
Ch4

=
=
=
=

'-';
'A';
'';
'';

Labell->Caption = "";
Fl(Chi);
F2(Ch2);
F3(Ch3); *
F4(Ch4);
Labell->Font->Color = clRed;

' .)

ButtonlClick Buttonl : Fl F4, : Chi Ch4. . , -

C++

27

. ,
, .
TLabel Caption .
FlF4 , , Ch, , Chi, .
TForml::ButtonlClick, ChiCh4 "-", "", "" "", Caption Labell, , FlF4, . .
Font Labell. , Color . TForml::ButtonlClick.
1.2.4.2
,
.
. , TForml
TLabel *Labell;

Labell TLabel.
, , . 2 . 2.8,
, ,
. , C-t-+Builder
, .
( )
. ( " " ">", , .. "->")
(.).
,
.
, , F1 F2. Labell>Caption.
: Caption Labell. To Caption
(*Labell).Caption. (*Labell) ,
.
,
C++Builder . .
. . , Font , . , , Color . Labell,
Labell >Font>Color (. TForml::ButtonlClick).
: Color Font, Labell.
. , , , Hide,
. - Labell ,
Labell->Hide();

28

1.2.4.3 ,

, ,
. ,
, - -. -
C++Builder .
. 1.2.4.1 F1 F2
, Ch2, Ch3 F3 F4 . ?
(
TForml),
. , ,
"::" . . 1.9.13.
Fl, F2 ButtonlClick
TForml::Fl, TForml::F2 TForml::ButtonlClick. ,
TForml. F3 F4,
, .
, ,
.
(, F1), . ,
, F1,
- - F1, Forml::Fl. ,
, ( , ).
.
,
. , .
C++Builder . , ,
, , ,
.
, ,
, , . , , ,
, , .
F3 F4 Forml>
. Caption Label 1
Forml->Labell->Caption.
Forml ,
.
, .
TForml::Fl, TForml::F2 TForml::ButtonlClick
Labell .
, ,
TForml (
MDI), , . ( -

C++

29

Ch2 Ch3) . , ( ), , . .. TForml Chi, . ,


, , - ,
. ,
, .
, , , . -
fastcall. He , , , . - .
, . ,
, (
, - ).
.
- (::).
-
fastcall.
- - - .
, ,
- () - () (>) ( )
(.).

1.3
: . ,
, , , .
C++Builder .
Run | R u n , , F9. , , . . , . , .
, . 1.2. .
:
( . 1.2 Unit2.cpp) (Linking). (Current
line), , (Total lines).

(Hints), (Warnings) (Errors). Cancel .

30

, . , ,
, .
. 1.2

| Project

DA..

[Compiling:

Untt2.<

CurrentIne; ....:.

i Hints:

j Total lines:

ngs:

0 j Errors:

Cancel

, , , . .
Run ,
- .
R u n Parameters
.
.
, - .
: Project Compile Unit,
Project | Make Project Project Build Project.
Compile , .
,
. ,
.obj .
Make ,
.
, .obj
. ,
.. , Make R u n , .
Build Make , , . , .
. , ,
, , . , Build, . .
: Project | Make All
Projects Project | Build All Projects. Make
Build, , .
C+-t-Builder 6 . , C++Builder 5,
.

C++

31

, , , . , . ,
, :
, . , -
, ,
. , Tools | Environment Options Preferences Background Compilation.
, ( Run) . 1.2. : "Done: Make"
": ", "Done: There are errors"
": ", "Done: There are
warnings"
": ".
C++Builder
[1].

1.4
.
: ,
,
.
"#" . , "#", .
.

1.4.1 #include
#mclude , . #include:
tinclude <_>
tinclude "_"
^include

,
include '<', ' ' '. , , , #include.

.
"<" ">", , '
(include directories).
, ,
:
, #include
, #include

34

:
_()
, #define,
. ,
.
,

.
, , :
Idefine CIRC () (3.14159 * () * ())

, CIRC (), . ,
S = CIRC ( 4 ) ;

'

:
S = (3.14159 * ( 4 ) * ( 4 ) ) ;

, S .

S = CIRC( + ) ;
:
S = (3.14159 * (a -t- b) * ( + ) ) ;

, . , .

.
(4) ..
:
S = 3.14159 * + * + ;

(. . 1.9.16) 3.14159 * , * , . ,
.
. , .
,
.
: ,
,
#define 11(,)

(3.14159 * ( ) * ( ) )

:
S = E l l ( R l , R2) ;

. ,
:
-

C++

35

double circ(double x)
{
return 3.14159 * x * x;
)

:
S = circ(a + );

, , :
.

. .
, , .
, , , . , . ,
.
+ , , . ,
. , -
, .
.
,
. , . , CIRC, , :
S = CIRC(a++)

(.
. 1.9.2) 1, :
S = (3.14159 * (++) * ( + + ) ) ;

, . 1, 2.
:
S = CIRC(++a)

1 , :
S = (3.14159 * (++) * ( + + ) ) ;

,
:
S = (3.14159 * ( + 1) * ( + 2 ) ) ;

, circ.
. , , (inline . . 1.7.6). , , , .

36

1.4.2.3 #undef

#undef, :
tundef

. ,
#undef . #define.
, :
tdefine MyConst 128
// MyConst 128
tundef MyConst
// MyConst
#define MyConst 64
// MyConst 64

1.4.3 : #if, #endif, #ifdef,


tfifndef. #else, #elif
.
. , sizeof , .
#if if.
:
#if

#endif

. (), , #if #endif, . (), , .


, ,
defined

defined 1, #define, 0 . , :
#if defined Debug && !defined MyConst


#endif
,
tdefine Debug

tdefine MyConst

C++

37


#undef MyConst

#if defined
#ifdef, #if ! defined #ifndef. ,
#ifdef

Size

#endif

#if defined Size


...

#endif

.
#elif ( else if if)
#else ( else if). ,
#if 1
1
#elif 2
2
#else
3
#endif

1 , 1,
2 , 2, 3 , .
. , , .
, ,
#ifdef Debug

#endif

,
#define Debug

.
#define,
Debug, . , , Conditionals
Directories/Conditionals , Project
Options.
, :
Debug, true :
#if (Debug)
(

Debug false, . , -

38

, .
.
.
,
, C++Builder :
ifndef UnitlH
define UnitlH


#endif

? #include,
. Unitl.h, UnitlH
. . #include , ,
UnitlH , .

1.4.4 #error, #line, #pragma


# :
terror errmsg

:
E r r o r : f i l e n a m e line# : Error directive: errmsg

errmsg , #. .

, .
:
tifndef UnitlH
terror He U n i t l . h

#line

. :
#line _
#line "_"
_ .
, . , , . #line , . . :
#line 100 " U n i t l . c p p "

#line C++Builder
. , ,
, .
#line.

C++

39

#pragma :
Ipragma

, .
C+4-Builder. .
#pragma . :
(finclude <vcl.h>
tpragma hdrstop

hdrstop. , , , .
#pragma hdrstop
. ,
- ,
.
#pragma:
#pragma package(smart_init)
#pragma resource " * . d f m "

,
.
, .dfm , . ^
.
:
#pragma m e s s a g e ( ) ;

tpragma message();

, , #define. #pragma message


. , , Projects | Options,
Compiler Show general messages.
, ,
Buttonl
#pragma message(" T F o r m l : r B u t t o n l C l i c k " )

Idefine text " T F o r m l : : B u t t o n l C l i c k "
tpragma message (text)

:
[C++] Unitl.cpp(l):
[C++] Loaded cached pre-compiled headers
[C++] TForml:rButtonlClick
[C++] TForml::ButtonlClick
[Linker]

- , , ,
.

40

1
#pragma startup _
#pragma exit __

,
, , WinMain
main. , _exit. . , , .

. ,
void

func(void);

. ,
, , ,
, , #pragma startup.
, . 64 255. 0 63 C++ .
0. 100. , , .
- , , - , . . :
void f I ( v o i d ) ;
void f 2 ( v o i d ) ;
tpragma startup f l
#pragma startup f2
A n s i S t r i n g ="";
void f 1 ( v o i d )
(
if (! InputQuery(", ",
", ", Name))
ShowMessage(" , ");
else ShowMessage(", " + Name + " !");
}
void f2(void)
(
ShowMessage(" ");
}

. , , , fl
. . 4 InputQuery. Name
.
fl f2, ,
.
f 1
#pragma startup fl 101

f2, 100,
fl.

C++

41

1.4.5 # ##
# , (). ,
. , :
#define P e r s ( x ) Labell->Caption = " " #

Pers();

Labell->Caption =

"

"

""

"" # . , , ()
,
Labell->Caption = " "

## (, ) .
,
#define C o n c a t ( x , y ) x ##

Concat(Edit,l)
Editl.

1.5
1.5.1
. 4 : , , ( ) . : 25 -5
, 4.8, 515, 515, -5.18 , '', '\0',
'\', '007' , " " - .
, . , ( 0 7). : 032. 08 , 8 .
037777777777. ,
, .
X ,
( 0 F, ). : OXF01.
OxFFFFFFFF. , , .
. char, signed char unsigned char.
. , '\0'. .
, . :
" , " " "

42

" , "
" "


" , "

, , '\'. ,
" , \
"

.
, . ,
"\"4MH\"\t XtAflpec\nMBaHOB\t \tMocKBa"


""

"\" ,
. "\t" "\" .
"\",
. ,
": \\test\\test. "

( )
"c:\test\test.cpp"
:
enum ();
,
enum color { red, yellow, green } ;

color,
red, yellow green.
color .
, : red 0, yellow 1, green 2. ,
. ,
enum color { red, yellow = 3, green = red + 1} ;
, : red 0, yellow 3, green 1. . .
C++Builder ,
true , false , NULL .

1.5.2
, . .

.

C++

43

. , 55,
- ,
if

(N > NMax)

...

,
if (N > 55) . . .

, NMax, 55,
, , .
, (. .
1.6.1), const:
const _ = ;

:
const f l o a t Pi = 3.14159;

,
. , Pi,
const f l o a t Pi2 = 2 * Pi; //
const f l o a t Kd = P i / 1 8 0 ;
//

:
const

maxint

= 12345;

, ,
int. , "const Pi = 3.14159;" Pi
3, .
-
.
:
char *const strl = "!";
char const *str2 = " ! " ;

strl, . str2 . . , . ,

str2 = strl;
,
[
strl = s t r 2 ;

1.5.3 (manifest)
C++Builder ,
(manifest) .
.
, .. ( ) ( ). . -

44

. Borland
C++Builder.

_ __ _

_ _BCPLUSPLUS_

0x0530

,
C++;

_ _BORLANDC_ _

0x0530

_ _CDECL_ _

,
cdecl

_CHAR_UNSIGNED

, ,
char unsigned char;

_ _CONSOLE_ _

_CPPUNWIND

,
;
xd

_cplusplus

C++

_ _DATE_ _

(
"Mmm dd yyyy", ,
"Jan 19 1994")

_ _DLL_ _

WD

_ _FILE_ _

_ _FLAT_ _

flat 32

_LINE_

_PASCAL_

,
Pascal

_STDC_

,

ANSI. ,

_TEMPLATES_

C++, ,

_TIME_ _

( "hh:mm:ss")

_WIN32_ _


GUI

_ _DATE_ _, _ _FILE_ _, _ _LINE_ _, _ _STDC_ _ _ _TIME_ _


#define #undef.

C++

45

1.6
1.6.1
,
, . .
:
_;

,
. :
int x l , 2;

. :
int xl = 1, 2 = 2;

, , .
:
int xl = 1, 2 = 2 * xl;


, , , :
for ( int i = 0; i < 10; i++)

1.6.2
,
, . , , .
C+-l-Builder : auto, register,
extern static.
, .
( ) , (, ,
, ..) . , .
, , . . , .
, "{}".
- .
:
. auto register
. .
, ,
.

46

auto, ,
. :
auto float x, ;


, auto .
.
, , :
{
int 1 = 1;

.
i ( ) . 1 . . , - .
register ,
, . :
register int i = 1 ;

, ,
,
. .
register. ,
, . , .
register .
, , , .
,
- .
volatile. :
volatile int tik;

volatile , - . , - , , ,
.
, .
C++ volatile (. . 2.14)
-. , ,
volatile, -, volatile.

C++

47

extern static ,
.
.
.
: ,
static. extern.
- . , .
, ,
, . .
, static,
, .
, static
. ,
.
, i
:
{

static int i = 1;

i . i 1. 2. i 3. ,
, , , , .

, . , .
extern . , , Unitl Unitl.cpp Unitl.h
( )
int a = 5;

, Unit2 Unit2.cpp Unit2.h



extern int ;

, . .
#include (. . 1.4.1), Unitl
.
. 1.8.

48

1.7
1.7.1
,
. , , , , .
, .
,
I = 5 * F(X) ;

F X, 5
I.
, . :
F(X) ;

.
:
__ _(_)
(

}

, ,
, . , .
, .
void.
, int. , .
,
main.
, .
, , ( )

_
, :
double FSum(double X I , d o u b l e X 2 , int A)

FSum, XI, 2 ,
double, int. double. XI, 2 , ..
' , .
.
. 1.7.2.
, :
void S P r i n t ( A n s i S t r i n g S)

, , - .

C++

49

,
, void. :
void F l ( v o i d )

void Fl ()
,
.
, C++
. ,
(..
, ). C++ . , , , C++.
( ),

. ,
";" . , . - ,
.
. ,
,
,
.
:
double FSum(double XI,double 2 , int ) ;
void S P r i n t ( A n s i S t r i n g S ) ;
void F l ( v o i d ) ;

double FSum(double, double,


void S P r i n t ( A n s i S t r i n g ) ;
void Fl () ;

int);

.
-, ,
- . , , . -, , .

. , . , , , ( ), . ,
.
, - , . , ,
#include (. . 1.4.1), , .
. , (, printf) -

50

.
"...". . :
int prf (char * f o r m a t ,

. . .) ;

format char
* (, ) .
void Fp ( . ' . . ) ;

.
, .

extern static. extern , . , extern, (.
. 1.8.1). static,
s t a t i c void F ( v o i d ) ;

.

.
.
, , , , .
. , .
, . .
- , . ,
"::", ..
.
, , . ,
static ( . . 1.6.2).
.
,
,
return. ,

return


, .
:
double FSum(double XI,double X 2 , int A)
{
return A * (XI + 2 ) ;

C++

51

, :
void S P r i n t ( A n s i S t r i n g S)
j
if (S != " " )
ShowMessage(S);
}

. , return:
void S P r i n t ( A n s i S t r i n g S)
{
if (S == " " ) return;
ShowMessage (S);
}

- (. . 1.12.6). Abort,
"" EAbort, - . , Abort .
-
. , .. . , . , n! = n x (n-1) x (n-2) x ... 1, , 1! = 1 0! = 1. for ( , , ).
n! = n x (-1)!. . factorial :
unsigned long f a c t o r i a l (unsigned long n)
{

if (n <= 1)

return 1;

else

return n * f a c t o r i a l ( n 1);

n 0 1, 1.
n , factorial, , . , 1. .

1.7.2

, , , . ,
double FSum(double XI,double X 2 , int A)

XI, X2, .
:
P r ( Y , X2, 5);

'

52

, . . XI, 2, , Y, X2 5. XI,
2, . XI, 2 ,
.
.
, .

.
- , , , .
, , ,
.
,
.
.
, .
,
;
,
.
:
. . , , "&";
. . ,
int &count
int & count
ints count

"count int". ,
. ,
, "&". .
:
void square(int & ) ;

//

void s q u a r e ( i n t & )
{
*= ;
}

//
//

. :
int xl = 2;
square (xl) ;

xl 4.

C++

53


,
, . ,
.
(. . 2.8 . 2).
"&", "*". "*", , , .

"*", (
. 2.8 . 2). , ,
"&".
square, :
void s q u a r e ( i n t * ) ;

//

void s q u a r e ( i n t *a)

//

* *= *;

//

, , int xl = 2;
square(Sxl);

1.7.3 const
.
: , , . : .
.
.
const.
( , const ) :
double F ( c o n s t & A )

,
. : "Cannot modify a const object".
, , .
: , , -

54

. .

, ,
.
.
const .
,
, , , , . , :
void F ( c o n s t char * s P t r ) ;

, sPtr, const char * ( ).


, . () , . ,
.
,
, . , , .
.
.
:
void F( char *const s P t r ) ;
.
. ,
,
, , . :
void F (const char *const sPtr);

1.7.4

. ,
, .
"==", . , ,
, ,
V , (, ) 2.
, , ,
( , ), : F = G * V * ( P 2), G .
, , :
double A r h ( d o u b l e V = 1,double P = 0.5,double PH20 = 1,double G = 9.81)
( return G * V * (PH20 - P ) ; }

. V
1 3, 0,5 / 3 ( -

C++

55

), 2
1 /3, G 9,81 /2.
,
. ,

F = Arh();

F .
() .
, .
,
F = Arh (2) ;

, 2 3
.
F = Arh(2,2.6);

, ( 2,6 /3)
2 3 . , , ,
,
, ,
( ).
,
, .

. , :
F = Arh(2,,1.1);

//

. , .

1.7.5
.
:
_(_, . . . )

( ),
. stdarg.h va_list : va_start,
va_arg va_end.
va_start :
void v a _ s t a r t ( v a _ l i s t , l a s t f i x )

,

. lastfix
.
va_arg :

56

1
type v a _ a r g ( v a _ l i s t ap, type)

. type
. va_arg va_start va_arg. va_arg
.
va_end :
void va_end(va_list ap)

, . , va_arg . .
. average, Labell . , .
.
:
tinclude <stdarg.h>
void a v e r a g e ( A n s i S t r i n g m e s s , . . . )
{
double A = 0;
int i = 0,arg;
va_list ap;
va_start(ap, m e s s ) ;
while ( ( a r g = v a _ a r g ( a p , i n t ) ) != 0)
{
i++;
A += arg;
}
Forml->Labell->Caption = mess + "N = " + I n t T o S t r ( i ) +
", = "+FloatToStr(A/i);
va_end(ap);
}

, , :
average(" : " , 4 , 2 , 3 , 5 , 4 , 0 ) ;

Labell :
: N = 5, = 3 , 6

average ,
( 0), N, :
void a v e r a g e ( A n s i S t r i n g m e s s , i n t N , . . . )
{
double A = 0;
va list ap;
v a _ s t a r t ( a p , N) ;
for (int i = 0; i < N; i++)
A += va arg ( a p , i n t ) ;
Forml->Labell->Caption = mess + "N = " -UntToStr (N) +
", = " + F l o a t T o S t r ( A / N ) ;

va_end(ap);

, , :
, average(" : " , 5 , 4 , 2 , 3 , 5 , 4 ) ;

C++

57

1.7.6 inline
, . C++
(inline) . inline , .
(. . 1.4.2.2). , , , .
inline,
, .
inline
. inline
, . , inline , .
inline , -
, . .
inline. , ,
,
R. , :
inline double C i r c ( d o u b l e R) { r e t u r n 6 . 2 8 3 1 8 * R; )

Circ(2)
"6.28318 * 2" ( ).

1.7.7
C++ ,
( ). . C++
, .

, ,
.
.
, , ,
(char *) ,
, . , , , ToS, ,
.
:
char * ToS(char *S,int X)
(return strcat (strcat (S, " ") , IntToStr (X) . c__str () ) ; }
char * ToS(char *S, double X)

58

1
{ r e t u r n strcat (strcat ( S , " " ) , F l o a t T o S t r ( X ) . c _ s t r ( ) ) ; }
char * ToS(char *S, bool X)
( i f ( X ) return s t r c a t ( S , " t r u e " ) ;
else return strcat (S," f a l s e " ) ; }

, , :
char S[128] = " =";
char SI = ToS ( S , 5 ) ;

char S[128] = " =";


char S2 = ToS (S,5.3) ;

char S[128] = " =";


char S3 = T o S ( S , t r u e ) ;

, double, . , , .
,
. , Area
R, , , :
double Area(double R) { return 6.28318 * R * R; }
double A r e a ( d o u b l e a, double b) ( return a * b; }


51 = A r e a ( l ) ;
52 = A r e a ( 1 , 2 ) ;

, .
.
( ),
. , . .

.
.
,
, .
; .

, , , , . ,
, , .

C++

59

1.7.8
.
, , . .
, , C++
. , .
template,
,
"<" ">".
class.
, . ,
.
.
. . class
.
,
( ) :
template <class T>
m i n ( T x l , 2, )
{
Irain = x l ;
if (x2 < Imin)
Imin = x2;
if (x3 < Imin)
Imin = x3;
return Imin;
}


, min.
( min) xl .
Imin.
, , :
int 11 = 1, 12 = 3, 13 = 2;
double rl = 2 . 5 , r2 = 1.7, = 3 . 4 ;
AnsiString si = " 1", s2 = " 2", s3 = " 3";
Labell->Caption = m i n ( i l , 1 2 , 1 3 ) ;
Label2->Caption = m i n ( r l , r 2 , r 3 ) ;
Label3->Caption = m i n ( s 3 , s2, s i ) ;

min ,
, min, C++
. . , .

60

,
:
int m i n i int x l , int x2,
{
int Imin =
xl;
if (x2 < Imin)
Imin = x 2 ;
if (x3 < Imin)
Imin = x3;
return Imin;
}

int

x3)

, <.
typename. , , ,
. C++ .
C++Builder 6 .
typename, -, class
. :
template <typename T>]
, .
,
class.
typename
.

1.8
1.8.1 ,

, . . , "{ }".
, ,
.
, ( ),
. . , , . ,
, .
( , , start:) , .
, ,
. switch (
case) goto (. . 1.10.1.2 1.10.1.3). , .

.
, ( ),
. -

C++

61

. , .
, , , , .
.

,
() . , ,
,
.
:
int i = 1, k = 4
{
int i = 5 , j = 2 ;
...

int i = 7;
...

}
...

//
//
// j , k
// i
// i
// j , k
// i
// j , k
// i

, . . ,
. , - .
i
, , 7, .
(auto) ,
static. :
s t a t i c int i = 7;


. ,
- . ,
(. . 1.6.2).
, .
"::". , ::1 I,
I.
, ,
i = : :i + 1;

i i.

62

, , ,
.

, (.
. 1.7.1). .
, . , , ,
.
,
. Unitl Unit2 Unit2 ,
Unitl. Unit2 , Unitl, .. - . ,
, ( ) Unit2
extern. , Unitl
int al = 10;

Unit2 ,
extern int al;

, , #include Unitl.h Unit2, .


, . Unitl al, Unit2 #include
Unitl.h,
extern ( al), Unit2 al, Unitl. , al Unitl.
Unitl Unit2 al.
.
. , , .
,
. Unitl
F, Unit2 :
#include Unit2
Unitl.h
Unit2 ( )
F
F
Unit2.
F Unitl , , Unit2 .

, static. :
static void F ( v o i d ) ;

C++

63

.
, , . .
( )
extern.
, ,
. . , #include ,
.
, , .
.
.
( ), private,
. ,
,
, .
,
, private.
, public,
, #include .
, , .
, , protected . , protected, ,
.
, , .
, , ,
.. . ,
, .
static.
, ,
. , , ( )
extern.
,
, , , .

"::".

64

1.8.2
namespace using
. . , , , . , .
namespace using.
:
namespace _
{
,
}

:
namespace A(
int 1 = 1;
void Fl (int i)
<
Forml->Labell->Caption = " A: i = " + IntToStr (i) ;
}
}
namespace B{
int i = 2;
void Fl (int i)
<
Forml->Labell->Caption = " : i = " + IntToStr (i);

.
i F1.
- . .

.
"::". ,
: :F1 ( A : : i ) ;

F1 i .
, . ,
, .
using. using:
using namespace _;
,
using namespace A;

C++

65

. ,
, - using
Fl(i);

F1 i .
using ,
:
using _ : : ;
,
u s i n g A : : F1;
u s i n g : : i;

Fl(i);
F1 i .
namespace
, namespace, , using namespace, . , . ,
:
namespace A {
)
namespace {
using namespace ;

namespace {


. . :
using namespace : : ;

1.9
1.9.1
. . , , . ,
"+" : X + Y . . , , . , "-" X "-".
, , . . 1.9.16.

66

1.9.2
,
. :

+Y

X-Y

X* Y

X/ Y

I %6

(-
)

+7


( )

-X

++

i++; ++i

i;i

.
"+" " "
, .
.
. , , .
.
( ) . .
, , .
. . 2 . 2.8.
"*" "/" . (. . 2.2). "%" .
. , ,
, :
1. , , .

C++

67

2.

, , .
.
"++" " "
"++" " " . , . L-, ..
. , ++( + ), ( + ) , .
, . , 1, "++", = + 1 += 1, . 1.9.4 "+==".
, . ,
.
, , . , .
,
int 1 = 1 , j ;
j = 1+ + * i++;

i 3, j 1. , j, :
i, 1, , .. ; j, i 1 1
.
:
int i = l , j;
j = ++i * ++i;

: i 3, j 9. , j
: i
2; i 3; i , .. j.

1.9.3

, . . EDivByZero
, . 1.12. , , . EIntOverflow. ,
,
. , :
int i = 2147483646;
int il = 1;

68

1
int
int
int
int

12
13
14
15

=
=
=
=

2;
1 + 11;
1 + 12;
13 * 13;

13 = 2147483647, 14 = -2147483648 15 = 1. , ( int), . ,


int 2147483647. 14 1, , , 1, .
15. . .

C+-t-Builder FPU (floating-point unit) ,
. , , , ,
, . , .
double = 1;
double = 0;
double z = /

.
float ;
double = 1.5-100;
= ;

,
float .
float = 120;
f l o a t = * ;

. , , , .

. FPU.
, , :

IE

DE

ZE

UE

1.

69

C++

.
:

IM

DM

ZM

PC

8, 9

RC

10, 11

. 0, ,
, .
(. . 1.12). 1, .
, :
"INF" ( ), "-INF" ( ),
"NAN" ( ). ,
.
.
SetExceptionMask, _cont!87, Set8087CW, . 4.
_contro!87, , , . 4. _contro!87 :
unsigned int _contro!87(unsigned int newcw,

unsigned int m a s k ) ;

newcw
FPU. mask . , mask 1.
.
,
__contro!87 (, ) ;

_contro!87(0, O x 3 F ) ;

unsigned int m = _ c o n t r o ! 8 7 ( 0 , 0 ) ;

m , .
, ,

. _status87.
. ,

70

1
if (_status87() & 0 x 4 )

ShowMessage(" ");

.

if (_status87() & 0x30)
ShowMessage(" ");
.
,
- , . - .
, . .
8 9 PC, . :

, float (1 )

, double (8 )

, long double (10 )

, FPU,
_contro!87. .
SetPrecisionMode . 4. , ,
double = 3;
long double z = 1 / ;

, z _cont!87 , :
PC

_control87(OxFOOO, 0x300)

0.333333343267440796

_contro!87(OxF200, 0x300)

0.333333333333333315

_contro!87(OxF300, 0x300)

0.333333333333333333

10 11 RC, . :
0

, ..

, ..

, ..

71

C++


_contro!87 ( . 4 SetRoundMode). , ,
float = 3;
f l o a t , z;
= 1 / ;
2 = -1 / ;

z _controI87
, , :

_control87(OxFOOO, OxCOO)

0,33333334327

-0,33333334327

_control87(OxF400, OxCOO)

0,33333331347

-0,33333334327

_eontrol87(OxF800, OxCOO)

0,33333334327

-0,33333331347

_contro!87(OxFCOO, OxCOO)

0,33333331347

-0,33333331347

RC

1.9.4 ,
Assign
C++ .

=Y

+=

+= Y

"=

,
, ,

,
, ,

-= Y

*=

*= Y

/=

/= Y

%'-

X %= Y

= Y

= Y

&=

&= Y

"=

~= Y

X =Y

72

"=" . , "=", .
, X += Y X = X + Y, .
: X %= Y X = X % Y .. (. . 1.9.2 1.9.6).

.
.
.
. , :
=

( = = 1)

+1;

.
1, 2. . ,
, (.. = 1). 1,
= 1. 1, 1 + 1. 2 .

Assign,
. Assign :
->!(_);

:
A->Assign(B);
( ) .
:
= ;

. Assign
. ,
. ,
( ),
. , ,
. , , , - .

1.9.5

. true , , false (0) , . :

73

C++

==

1 ==

N
<

X != Y

< Y

>

Len > 0

-^
>=

Cnt <= 1

1 >= 1

, , .
"<", "<=", ">", ">=" ,
.
"==" "!=" .
true false, .
: "==" "=". ,
i f ( == 2) ...;
\

if ( = 2)
. , C++
, , , , if. 0, false. true. = 2
true , , if . .
, C++Builder
if :
"Possibly incorrect assignment" ( ).
, . , .

1.9.6

: true false (0).

&&

&&

II

||

74

"!" true,
. , ! == 0.
"&&" true, . 0 (false), false. ,
, .
"||" true,
. 0 (false), false. ,
, .

1.9.7

, .. .

&

X&Y

I
*

| Y

X"Y

YI

" " .
"&", "|" " "
, 1 2 :

El & E 2

1 * 2

1 | 2

""
, . .
,
. .

2 .
""
, . ,
. 2.

C++

75

1.9.8 ()
",", ,
, . . void. . .
,
= 4;
b = + 5;


= 4, b = + 5;

:
_1, _2, . . . , _

, .
, . ,
f u n c ( i , (j = 1 , j + 4) , k) ;

, . : (i, 5, k).
for (.
. 1.10.2.1) . , for :
int [10] , sum, i;
sum = [ 0 ] ;
for (i = 1; i < 10; i++)
sum += A [i] ;

To :
int A [ 1 0 ] , sum, i;

for (i = 1, sum = A [ 0 ] ; i < 10; sum += A [ i ] ,

: ,
( i sum),
, ( sum i).
",".
. , , .

1.9.9 (?:)
"?:" - ()
C++, . :

76

1
? 1 : 2

, , ( ),
, ( ). ,
Labell->Caption =
grade > 3 ? " " : "";

grade " " grade, 3, "" grade.


,
if...else (. . 1.10.1.1).
if...else.
,
if...else .
. (, , , ),
. - .

1.9.10 sizeof
sizeof ,
, . size_t (unsigned).
:
sizeof
sizeof ( )
:
sizeof *Labell;
sizeof(TLabel);
sizeof a;
sizeof (int);

,
(*Labell), (TLabel, int), ().
, , , . , , , sizeof.
, sizeof
, , .
, ,
(.. ). sizeof array/
sizeof array[0].
, , . sizeof
.
sizeof , , .

C++

77

1.9.11 typeid
typeid type_info,
. :
typeid( )
typeid( )

, typeid , . , .

1.9.12 (&) (*)


"&" , "*" . . 2.8.
. 1.7.2.

1.9.13 (::)
, "::". :
:

::
:

:: _


,
. , ::1 I,
I. () . . 1.8.
- - , , . - .
, C++Builder, .

1.9.14 : (.) (->)


: "." ">". , . ,
Prop F(), :
A.Prop
A.F()

, C++Builder,
. :

78

1
Labell->Caption
Labell->Hide()

, , , , :
(*Labell).Caption
, .

1.9.15 () ()
"" ""
, cout cm,
, (. . 2, . 2.10.3.1).
,
outfile infile
.
#include < f s t r e a m . h >
// outfile, "Test.dat"
ofstreaift o u t f i l e ( " T e s t . d a t " ) ;
if(loutfile)
{
ShowMessage(" ");
return;
)
...

//

outfile.close();
//
// infile, "Test.dat"
ifstream infile("Test.dat");
if(!infile)
{
ShowMessage(" ");
return;
}
...

//

infile.close();

//

. . 2, . 2.10.3.1.
, .. "". ""
, . , , ,
,
, - , , ,
.
"" , , , . . ,
o u t f i l e "!' 1 ;
"!".

C++

79

int i = 25;
o u t f i l e i;

"25".
"" , ..
. , ,
outfile " 2 * 2 = " (2 * 2 ) ;

" 2 * 2 = 4". ,
"2 * 2 = " outfile,
o u t f i l e (2 * 2 ) ;

.
, , . Memo,
OnClick :
char sin [80];
ofstream outfile("Test.dat");
if(!outfile)
{
ShowMessage(" ");
return;
}
// , :
outfile "2 * 2 = " 2 * 2;
//
outfile.close ();
//
ifstream infile("Test.dat");
if(!infile)
{
ShowMessage(" ");
return;
}
Memol->Clear ( ) ;
while(!infile.eof())
{
infile.getline (si,80);
Memol->Lines->Add(AnsiString(si));
}
//
infile.close();

. 2.10.3.1.
, "Test.dat", outfile,
"" , .
, infile, Memol.
"". ( ) ,
. ,
"\" endl (
end line ). ,
o u t f i l e "2 * 2 : \ " (2 * 2) " \ " ;

80

o u t f i l e "2 * 2 :" endl (2 * 2) endl;

: "2 * 2 :", - "4", .


.
. ,
int i = 25, j = 2;
o u t f i l e i " * " j " = " (i * j) endl;


int i = 25, j = 2;
char s[80] = "25 * 2 = ";
o u t f i l e s (i * j) endl;

: "25 * 2 = 50".
, char * .
AnsiString (. . 2.5.2, 3.1.6, 3.4.2.3) "" .
char * c_str:
' A n s i S t r i n g sa = " A n s i S t r i n g " ;
o u t f i l e s a . c _ s t r ( ) endl;

. Editl
Edit2, , :
int i = S t r T o I n t ( E d i t l - > T e x t ) ;
int j = S t r T o I n t ( E d i t 2 - > T e x t ) ;
o u t f i l e i (i == j ? " " : " ") " " j
endl;

"... ..." "...


,..".
, . , (. . 1.9.16) i, .
"" . ,
o u t f i l e Memol endl;

"0063F610" Memol.
char *.
, , s, , . "" . , (void *). :
o u t f i l e (void * ) s endl;


"". , , "". endl. . 2, . 2.10.3.2.
"". , , ,

C++

81

. , . .
,
infile i j ;

, , infile, i j.
, .
, , . , ,
o u t f i l e i ' ' j endl;
.
o u t f i l e i j endl;

.. ,
i, j .
"" char *.
, :
char s [ 8 0 ] ;
i n f i l e s;

s. ,
, .
, 0. , , ,
, :
while (infilesl)

1.9.16
, , .
16 , .
. , , . ,
, .
, (,
), ,
.

, , .
, ,
, new delete, . 1.11.

0 -> "
+ - ++ & * sizeof new delete

82

* _> *

*/%
+
< <= > >=
i
&
I
&&
I

?:
= *= /= %= += -= &= "= = = =

, + b * / d + (( * ) / d). , , .
, b * ,
. .
, ,
.

1.9.17
C++ , ".", "*", "::", "?:" sizeof.
" = " , " [ ] " , " ( ) " "->" -. .
, -
, . ,
C++. ,
, .., , .
(
), , ,
operator, . , operator+ .
,
, . "="
. - .
, ;

C++

83

. "&"
;
. .
.
. ,
.
.
, . , , .
,
, , C++ . ; , , .

Complex, , . , , .
class Complex {
public:
double Re;
//
double Im;
//
Complex(double = 0.0, double = 0.0); //
//
Complex operator* (const Complex &) const; //
Complex operator* () const;
//
//
Complex operator-(const Complex &) const; //
Complex operator-() const;
//
Complex &operator=(const Complex &) ;
//

};

//
Complex::Complex(double R, double I)
(
Re = R;
Im = I;
}
//
Complex Complex::operator+(const Complex &X) const
{
Complex R;
R.Re = Re + X.Re;
R.Im = Im -I- X.Im;
return R;
}
//
Complex Complex::operator-(} const
{
Complex R;
R.Re = -Re;
R.Im = -Im;
return R;
}
//

84

1
Complex & Complex::operator=(const Complex SR)
{
Re = R.Re;
Im = R.Im;
return *this; //
}

-: Re
, Im . 0.

Complex operator+(const Complex &) const;


. , , . " 4- ", Complex, , , "A.operator+(B) ".

Complex o p e r a t o r + ( ) const;

,
.
.

R Complex, .
Re Im, ,
. .

Re Im. ,
*this. this .
,
. .
= , Complex, A.operator=(B). , = = ? ,
B.operator=(C).
A.operator=(B.operator=(C)). , , . ,
*this. .
, , :
Complex ( 1 , 1 ) , B ( 2 , 2 ) , C , D ;
= -;
= + + ;
D = - ;
= = ;

C++

85

1.10
1.10.1
1.10.1.1 if
if . , .
: if if...else. if :
if

()

, , .
, .
( true ), if
. if . ,
= ;
if ( > ) = ;

, =
> .
C++ ( )
( true,
false), . :
int , , ;
i f ( - /)

if(a b/c) if(a == b/c),


b/c /. :
double , , ;

if( - /)

- ,
/ .
. :
if

(int v = f u n c ( a ) )

. ..;

if, .
if...else :
if () !;
else 2;

true, , . ,
else .
.
if (J == 0)
ShowMessage(" " ) ;
else
Result = I / J ;

86

, , ,
:
if (J == 0)
{
ShowMessage(" ");
Result = 0;

)
else
Result = I/J;

, else .
if , if else. , else if,
else.
,
if (!)
if (2)
!;
'else 2;

else if, .. 2
, , . ,
if (!)
{
if (2) !;
else 2;
}

else if,
:
if

(!)
!

if () !;
}
else 2;

1.10.1.2 switch
switch
.
switch :
switch (_) {
case _1 : _1;
break;
case _ : _;
break;
default : ;
)

//
//
//

, .. , , ,
.
, case, , . ":", ( -

C++

87

), ,
.
,
case, , , ,
, . , , ,
, ,
break;

switch .
, , default. ,
default switch. , ,
.
, , .
.
, .
Key char, , . FYes, FNo,
.
switch ( K e y ) {

case '': case 'Y':


{ FYes(); break; }
case 'n': case 'N 1 : { FNo(); break; }
default : ShowMessage(" ");
}

,
,
case.
1.10.1.3 goto
goto
, .

goto . , goto
.
goto ,
. , , .

. ,
Lbegin:
, goto.
, goto, , . ,
, .
.
, , -

88

. switch ( case -- .
. 1.10.1.2).
, .
goto :
goto ;

, goto , , :
goto L1;

second: . . .
LI:

...

if (...) goto LI;


else goto second;

, , ,
goto.

1.10.2
1.10.2.1 for
for
( , ) . . (),
. ,
.
for:
for

(!;

2;

! , ,
2 ,
.
for . ! ( , ..
. . 1.9.8).
( ) .
2 . (
true ), ,
for. , . ,
2,
. - 2 false ( ), , for.
for. ,
Data 10:
int Max, Sum;
= Sum = Data[0];
f o r ( i n t i = 1; i < 10; i++)
{
if (Data[i] > Max) Max = D a t a [ i ] ;
Sum += D a t a [ i ] ;

C++

89

for i, , 1.
. ,
1, , , 9. for i 1 .
i for.
. i
.
BCC32.EXE,
, , , -Vd.
for
(. . 1.9.8).
. , i Sum ,
for:
int Sum,i;
f o r ( S u m = D a t a [ 0 ] , i = 1; i < 10; Sum += D a t a [ i + + J ) ;

for ,
Sum, , i.
for
i. for , .

. , , . . ,
, Editl, .
,
.
AnsiString s;
char Key = 'A' ;
s = Editl->Text;

for (int i = s.Length(); i >0; s[i ] = s[i] Key);


Editl->Text = s;

, i , Length(). i 1 .
,
for
Length(), .
Length() .
for . ,
- . ,
,
. , -
goto , . 1.10.2.4. for , .

90

- ,
( ) . ,
f o r ( ; i<10;)

.
, for .
for .
for, Mat,
Mat! Mat2 . . :

Mat[l, J] = Matl[l, ] Mat2[K, J].


K=l

int I, J, , X;
f o r ( I = 1; I <= ; I++)
f o r ( J = 1 ; J <= M; J++)
{
X = 0;
f o r ( K = 1; <= ; ++)
X += M a t l [ I ] [ K ] * M a t 2 [ K ] [ J ] ;
Mat [I] [J] = X;
}
1.10.2.2 do...while

do...while , , ,
. do...while:
do while ();

. .
,
. true ( ), . , false ().
, do...while.
, ,
. , ,
false. , ,
.. . .
- , , break , . 1.10.2.4.
do , - . , ,
.. . , , .
- , while ,
. ,
.
, .

C++

91

, while (. . 1.10.2.3).
, for (. . 1.10.2.1).
, Filel.txt ,
( ), Editl. strstr. feof.
FILE *F;
char S [ 2 5 6 ] = "";
A n s i S t r i n g SKey = Editl->Text;
i f ( { F = f o p e n ( " F i l e l . t x t " , " r " ) ) == NULL)
{
ShowMessage(" ");
return;

do
fgets(S,256,F);
while ( !feof(F) S& (strstr (S,SKey.c__str () ) == NULL) ) ;
fclose(F);
if (strstr(S,SKey.c_str()) == NULL)

, ,
strstr NULL ( ).
( ),
.
1.10.2.3 while
while
, . while:
while () ;

. , . true
( ), , , . ,
false (). , , while.
, , , .
,
false. , , .. . .
-
, , break, , , . 1.10.2.4.
while
, - .
, , ..
. , , . - , while , .

92

( ),
.

Filel.txt ,
Editl. do...while, while.
,
, .. .
, .
FILE *F;
char S[256] = "";
AnsiString SKey = Editl->Text;

i f ( ( F = fopen ( " F i l e l . t x t " , " r " ) ) == NULL)


(
ShowMessage(" ");
return;
}

while(!feof(F)&&(strstr(S,SKey.c_str()) == NULL))
fgets(S,256,F);
fclose (F);
if (strstr(S,SKey.c_str()) == NULL)

for:
for(; Ifeof (F) && (strstr (S,SKey.c__str () ) == NULL) ;
fgets (S,256,F));

while .
1.10.2.4 : break. Continue, return,
Abort
, - . ,
, - for, do while.
-
(). .
for, do while , .
break. , switch. break for, do while .
,
:
while ( Ifeof (F))
{
fgets(S,256,F);
if(strstr(S,SKey.c_str()) !=NULL) break;
}

goto, - , .

C++

93

, ,
return. break, return , , .
, , ,
- (. . 1.12).
Abort, , - .
.
Continue, , .
Continue,
. , ,
, , "*". :
w h i l e ( ! f e o f (F) )
{
fgets <S,256,F) ;
i f ( S [ 0 ] != ' * ' ) continue;
i f ( s t r s t r ( S , S K e y . c _ s t r ( ) ) ! = N U L L ) break;
}

, "*", . ,
strstr , .

1.11
. , , ,
. ,
, ..
. : , . , , ,
.
heap. : malloc, calloc,
realloc, free new delete.
stdlib.h alloc.h.
malloc :
void *malloc(size_t size);

heap size . . size = 0, NULL.


calloc :
void *calloc(size__t nitems, size_t s i z e ) ;

nitems , size. nitems * size.

94

. .
size = 0 nitems = 0, NULL.
realloc
. :
void *realloc(void *block, size_t size);

heap, block,
size. , block , malloc, calloc realloc. block
NULL, realloc , malloc.
size , ,
block, , NULL. ,
size 0 ,
, .
, realloc NULL. , . block,
.
free :
void f r e e ( v o i d *block);

, malloc, calloc
realloc, block.
.
malloc , , - , .
linclude <stdio.h>
tfinclude <alloc.h>
char *str;
// str ,
str = (char *) raalloc(lOO);
//
free(str);


calloc:
str = (char *) calloc(100, s i z e o f ( c h a r ) ) ;

malloc calloc , , :
str = (char *) r e a l l o c ( s t r , 2 0 ) ;

, :
realloc(str,

20);

, NULL (),
. , , , NULL.
.
:
new delete.
new malloc,
, malloc. ,

C++

95

C-H-Builder.
new :
<::> new <> <()>
<::> new <> () < ()>

.
, , . "::" new, . ( ) . .
, . :
double *A = new double;


. *. :
* = 5.1;
Labell->Caption = *;


,
:
double = *new double;

.
. :
double *A = new double (5.1);
double = *new double ( 5 . 5 ) ;

TEdit:
TEdit *Edit = new T E d i t ( t h i s ) ;
Edit->Parent = Forml;

,
this Owner. Forml. .
new
. ,
sizeof(THn).
,
new . .
,
delete .
,
bad_alloc.
catch (. . 1.12.5), ,
. ,
, ,
:
#include <iostream.h>
try

96

1
new
}
catch(std::bad_alloc)
(

}

bad_alloc,
, .

set_new_handler()

. set_new_handler
, .
,
void Fl(void)
{
ShowMessage("He ");
exit(l) ;
}

, , (, OnCreate )
set_new_handler ( F l ) ;


new,
bad_alloc, ( ).
,
.
bad_alloc, ,
set_new_handler(0);

new NULL.
, , NULL ,
new.
. .
,
double *A = new double [100];

100 .
, : A[ind]. new ,
, .
. ,
double *M = new double[100] [100];

.
, , . :
double * = new double[n] [ 100];

, . . delete.
,
free. delete . , new, delete.

97

C++

:
<::> delete <>
<>
<::> delete
delete < > [ ];

:
double * = new double (5.1);
delete A;

double * = new double[100];


delete [] A;

delete , NULL. ,
, :
delete A ;
= NULL;

1.12
1.12.1
: , , ..
.
- - ,
. .
, . - , .
(
), Application->HandleException. . . 1.3
StrToInt "1.5" .
C++Builder , , . 1.3 , C++Builder, .
, .
C++Builder . [1].
, , . 1.3



()
()

)
'i .5' is not a valid integer value.

OK

98

. , ,
. , , :
FILE *fp;
int size;
char *str;
fp = fopen("a.tmp", "w");
fprintf(fp," a.tmp");
str = (char *) malloc (size);
<, >
remove(".tmp");
free(str) ;

(. . 2.10.2) a.tmp, - . remove. (.


. 1.11) malloc, , , free.
, remove
free . , malloc,
,
a.tmp.
,
,
? ,
. 1.3 .
, . , , , Windows.
, ,

. - , , , ..

1.12.2 try ...


exit

finally

. try ...
finally. , ,
, :
try

// ,
}
__finally

// ,


finally , , . ,
, ,

C++

99

; ,

finally.
,
:
FILE *fp;
int size;
char *str;
try
<
fp = fopen("a.tmp", "w");
fprintf(fp," a.tmp");
str = (char *) malloc(size);
// ,
//
)
finally
{
remove(".tmp") ;
free(str);
}

remove free ,
try,
. , .
, .
, :
- , ( . 1.3 , ). ,
finally , ,
, .
ExceptAddr ExceptObject, ,
finally , .
. . .
exit:
tinclude <stdlib.h>
void e x i t ( i n t s t a t u s ) ;

status . 0 , ,
. , , status : EXIT_FAILURE , EXIT_SUCCESS .
:
exit(O);
exit(EXIT_SUCCESS);
exit(l);
exit(EXIT_SUCCESS);

//
//
//
//

100

exit ( ). .
- (,
), , .

atexit:
#include <stdlib.h>
int atexit (void (_USERENTRY * f u n c ) (void) ) ;

func . atexit, .
: , .
, myexitl
myexit2:
void myexitl (void)
{
//
}
void myexit2 (void)
(

//
}
, .
:
atexit (myexitl ) ;
atexit (myexit2) ;

, , OnCreate
.
exit myexit2,
myexitl, ( ),
.
myexitl, .tmp ( findfirst,
findnext remove . . 4):
void myexitl (void)
<
struct ffblk ffblk;
int D;
D = findfirst ("*. tmp", Sffblk, 0) ;
while (!D)
{
remove (ffblk. ff_name) ;
D = findnext (Sffblk) ;

exit .

C++

101

Close,
, . , . , , - , .

1.12.3 VCL
,
, . C++Builder .

. , , Exception () VCL,
, exception C++. .
1.12.5.
Exception VCL
,
EAbort


EAbstractError

EAssertionFailed
EBitsError
ECacheError
ECommonCalendarError


TBaseArray:
,
,

, Assert VCL Pascal
TBits

,
TCommonCalendar

EDateTimeError
TDateTimePicker
EComponent Error

EConvertError ( , StrToInt, StrToFloat, StrToDate)


EDatabaseError
EDBClient
. ErrorCode
, BDE

102

1
EReconcile-
Error

TClientDataset;
Context ,
de
, BDE
EDBEngineError BDE. Errors
TDBErrors.
Error-Count
ENoResultSet

TQue
SELECT

EUpdateError

vider

EDBEditError

EDimension

EDimlndex

External

, Windows
EAccessViolation

;
NULL, ,
,

EControlC


Ctrl+C .

, ,

EIntError


EDivByZero

C++

103

ERange



; Object Pascal
Elnt
Overflow

EMathError
; ;
EMathError


Elnvalid Argument


EInvalidOp
: ,

EOverflow


EUnderflow


EZeroDivide


EPrivilege
,

EStackOverflow

104


EExternalException
EHeapException
EInvalidPointer , ,

EOutOfMemory
; OutOfMe

EOutOf Resources
Windows,
Windows

;


Windows
EInOutError
- ; , I/O checking
Pascal ;
ErrorCode
EIntfCastError

EInvalidCast

Elnvalid
Graphic
Elnvalid , , Graphic Operation
Clipboard
ElnvalidGrid
Operation
ElnvalidOperation

;
, , , ( Parent = NULL). (,
Forml::BeginDrag).

105

C++

EListError

TStringList TStrings:
, TStringList,
Duplicates du,
,

ELowCapacity

,
; Capacity,

EMCIDevice


Media Control Interface (MCI)

EMenuError

EOleCtrlError

ActiveX

EOleError

OLE; C++Builder ,
EOleSysError

OLE,
OLE IDispatch; ErrorCode
.
EOleException

EOutlineError

OLE,

Outline
EOutOfResources


Windows, Windows ;
Windows

EPackageError ,
EParserError


,
- ( - )

EPrinter

; ,
, ,
-

EPropReadOnly OLE
,

EPropWriteOnly

OLE
,

106

EPropertyError

ERegistryException
EResNotFound .DFM
.RES .
EStreamError
EFCreateError
; ,
,

j
EFOpenError

EFilerError

EReadError
EWrite

EClassNot- Found

Elnvalid
Image

(, Synchronize Tthread
)
ETreeView View
Error
EUnsupported-


EVariantError , Variant
EWin32Error
Windows,
RaiseLastWm32Error, Windows

EStringListError
EThread

1.12.4 VCL Exception


C++Builder , , . 1.12.3, Exception, SysUtils TObject.
"

C++

107

1.12.4.1
Exception :

HelpContext

hit

- . , , , F I . 0

Message

System::AnsiString

,
;

Message ,
. , ,
Message string .
HelpContext - . , ,
, F l .
HelpContext 0.
(. ). ,
throw E x c e p t i o n ( " H e ", 4 ) ;

Message, " ", HelpContext, 4. Fl , .


, ,
, Help file (
) Project Options ( ) Application ().
1.12.4.2
Exception TObject, , ClassName.
, Exception 8 , :

Exception(const System::AnsiString Msg) , Msg Message


Exception(const System: :AnsiString Msg,
const System::TVarRec * Args, Message,
Msg
const int Args_Size)
Args Args_Size

108

Exception(int Ident)


Message Ident


Exception(int Ident,
const System::TVarRec * Args, Message Ident
const int Args_Size)

Args
Exception(const System::AnsiString Msg, int AHelpContext)
Msg Message; HelpContext HelpContext -

Exception(const System::AnsiString Msg,


const System::TVarRec * Args,
const int Args_Size,
int AHelpContext)


Message,
Msg
Args;
HelpContext HelpContext -

Exception(int Ident, int AHelpContext)


Message Ident
; HelpContext
HelpContext
-

Exception(int Ident,

const System::TVarRec * Args, Message
const int Args_Size,
int AHelpContext)
,
Ident, Args;
HelpContext
HelpContext
-

:
throw E x c e p t i o n ( " H e " ) ;
throw E x c e p t i o n ( F o r m a t ( " %d %d",
OPENARRAY(TVarRec, (N1, N 2 ) ) ) } ;

Format (. . 4) N1 N2. OPENARRAY ( . . 2 . 2.11.3). , ,


N1 = 5 N2 = 7 , : " 5 7".
:

C++

109

throw Exception(" %d %d",


OPENARRAY(TVarRec,(N1, N2)));

, . , .
- :
throw Exception("He ", 4 ) ;

, , F1,
4.
, :
throw E x c e p t i o n ( 6 5 3 6 9 ) ;

Message 65369
.
raise E M y . C r e a t e R e s F m t ( 6 5 3 6 9 , O P E N A R R A Y ( T V a r R e c , ( N 1 , N 2 ) ) ) ;

65369
Message N1 N2.

1.12.5 try ... catch


1.12.5.1 try ... catch
try ... catch. :
try

<


}
catch ( TypeToCatch )
{
,
}

catch . TypeToCatch (int, char ..),


, ,
.
. 1.12.6.1. ,
.

try , catch. try
catch . ,
catch - : , - (, ) .. , . catch , , .. .

110

. Editl Edit2, float. .


: , , , ,
float. :
float ;
try
{
= StrToFloat(Editl->Text) / StrToFloat(Edit2->Text);
}
catch(EConvertError&)
{
Application->MessageBox(" ",
" ",_);
}
catch(EZeroDivide&)
{
Application->MessageBox(" ",
" ",__) ;
}

catch(EOverflows)
{
Application->MessageBox("",
" ",_);
if (StrToFloat(Editl->Text) * StrToFloat(Edit2->Text) >= 0)
A = 3.4E38;
else A = -3.4E38;
}

(, , - ), StrToFloat EConvertError. .

( EZeroDivide). , catch , : .
, . 1.12.3,
,
. catch
. , EZeroDivide (
), EOverflow ( ), ElnvalidArgument ( ) EMathError. catch, , :
catch(EMathErrors)
,
{
Application->MessageBox(" ",
" ", MB O K ) ;
}

, .
, . Message, , .

C++

111

, catch
,
. .
, EMathError:
catch(EMathErrors E)
{
AnsiString S = " : ";
if(E.Message == "EZeroDivide") S += " ";
if(E.Message == "EOverflow") S += "";
if(E.Message == "EInvalidArgument") S += " ";
Application->MessageBox(S.c_str(), " ", _);
}

, Message .
, catch ,
:
catch(...)
(
ShowMessage(" .");
}

catch(...) catch,
, , .
, , , .
C++Builder . catch(...) ,
: "The handler must be last"
(" ").
catch(...).
- , .
1.12.5.2 ,

try...catch . try...catch,
try ,
try...catch. .
try...catch, . ,
try...catch ( ) ..
try...catch,
, . . , , , , .
catch, , , , try...catch.
,
. , . -

112

try...catch, ,
.
, .
OnException Application . .
MyException.
:
void

f a s t c a l l MyException(TObject *Sender, Exception * E ) ;

:
void
{

f a s t c a l l T F o r m l : : M y E x c e p t i o n ( T O b j e c t 'Sender, Exception *E)

//
}
MyException OnException. , , , OnCreate :
Application->OnException = MyException;

.
, . MyException ,
catch .
Exception. ,
Exception .
ShowException, :
Application->ShowException();

, ,
. 1.3. ,
. , - . . ClassName. OnException , ,
:
void
{

f a s t c a l l T F o r m l : : M y E x c e p t i o n ( T O b j e c t *Sender,
Exception *E)

AnsiString S = " : ";


if ((String(E->ClassName()) == "EZeroDivide")
|| (String(E->ClassName()) == "EDivByZero"))
S += " ";
if (String (E->ClassName()) == "EOverflow")
S += "";
if(String (E->ClassName()) == "EInvalidArgument")
S += " ";
if(String(E->ClassName()) == "EConvertError")
S += " ";
Application->MessageBox(S.c_str()," ",MB OK);

C++

113

. 1.4 , .
, . 1.4,
. 1.3.
. 1.4

,


()

()

.*i

1.12.6
1.12.6.1 throw
. , - , ,

try.. .catch.
, , .
throw.
:
try

//
try //
{
// ,
//
}
catch ( &)
{
// ,
throw;' //
}
// ;
//
} // try
catch ( &)
{
// ,

, , : , . ,
, . , , .
throw
, . , , , -
. , - , . , ,
. , .

114


throw, . catch,
, . ,
, ,
Editl, , , :
if(Editl->Text == "") throw "He ";
char *. .
, , catch:
catch(char * s)
Application->MessageBox(s, " ", MB_ICONHAND|MB_OK);

char *
, . 1.5.
. 1.5
,
char

*!

throw ,
. :
if

( . . . ) throw 1;

int.
:
c a t c h ( i n t & i)
{
switch ( i )
{

case 1 : . . .
break;
case 2 : . . .
break;

, ,
, . ,
, , , () . st
Pers
(st.il) .
(st.il) (st.i2) . , , st. .

C++

115

struct Pers
{

int il, 12;

1 st = { 0 , 5 } ;
try
{
i f ( . . . ) st.il++;

i f ( s t . i l < st.12) throw st;


}
catch (Perss)
{
Application->MessageBox((" - ' +
I n t T o S t r ( s t . 1 2 ) + " " +
IntToStr (st. 11) ) . c__str () ,
"He ",MB_ICONHAND | MBJDK);
}


. 1.6.
. 1.6

- 5
-1

1.12.6.2 EAbort Abort


C++Builder EAbort, . , ,
. catch , TApplication::HandleException , ,
. , ,
.
EAbort Abort.
:
if ( . . . ) Abort () ;

: Abort - -
, abort .
EAbort (,
Esc - ). Abort , . , . , - ,
try...catch :
catch(EAbort&)

116

1.12.7 C++
, C++Builder. , . C++ .
C++ , #include ,
(. . 5),
:
using namespace std;

. , std::bad_alloc.
C++ exception,
stdexcept. , , , ,
-: what (). ,
.
exception :

bad_alloc

new
(. . 1.11)
dynamic_cast,
bad_cast
,

, bad_exception

(. )
bad_typeid
typeid


ios_base::failure

logic_error

runtime_error


<new>
<typeinfo>
<exception>
<typeinfo>
<ios>
<exception>
<exception>


. , .
<stdexcept> logic_error:

C++

117

domain_error



invalid_argument
length error
- , ,
out_of_range
..
, ,
,
.
runtime_error , <stdexcept> :
range_error
overflow_error
underflow_error

0


0

C++ , , , ,
throw .
, what().
, , F, 1 R. ,
R , , ,
.
, . ,
, ( exception) - .
:
finclude <stdexcept>
u s i n g namespace std;
double F (double R)
if (R == 0)

throw overflow_error (" - ");


else
= 1 / R;

try
{

118

1
// F

double = F(B);
}

catch(exception & e)
(
//
ShowMessage(e.what() ) ;
}

,
,
throw, , . :
double F ( d o u b l e R) throw (overflow_error)

, , . :
double F ( d o u b l e R) throw ()

.
, - . unexpected, terminate. ,
F :
double F ( d o u b l e R)
{

throw

(overflow_error)

throw overflow_error(" - " ) ;


throw range_error(" " ) ;

overflow_error catch, range_error .


C++ , , bad_exception. terminate, , bad_exception, . C++Builder 6
. , . unexpected. set_unexpected, :
typedef void ( * unexpected_handler ) ;
unexpected_handler
set_unexpected(unexpected__handler unexpected

func);

, unexpected.
unexpected.
, :
void MyUnexpectedO
(
throw;

C++

119

. , ,
:
set_unexpected(MyUnexpected) ;

, ,
OnCreate .
, unexpected, -
, ,
:
unexpected_handler UH;
//
UH = set_unexpected(MyUnexpected);
//
UH = set_unexpected(UH);


unexpected, .
, F , :
try

// F
double = F(StrToFloat());
}
catch(overflow_error & )
{
// overflow_error
ShowMessage(e.what());
}
catch(exception & e)
{
//
ShowMessage(" : "
AnsiString(e.what ( ) ) ) ;
}

set_terminate
terminate , unexpected.

1.13
(),
. : , Ctrl-C, ,
( ), , ( ).
, signal.h ( . 4,
signal).

120

SIGABRT

(,
abort). _exit(3)

SIGFPE

, ,
, . _exit(l)

SIGINT

(, Ctrl-C).
INT 23h

SIGUSR1, ( Win32) SIGUSR2, , raise. SIGUSR3


signal,
. signal : .
.
raise, .
, SIGUSR1. Handl_SIGUSRl.
- (, OnCreate )

s i g n a l ( S I G U S R 1 , Handl^SIGUSRl);


tinclude <signal.h>

:
void Handl_SIGUSRl(int N )
{
if(MessageDig("?", mtConfirmation,
T M s g D l g B u t t o n s ( ) mbYes m b N o , 0 ) == m r Y e s )
// :
signal(SIGUSR1, Handl^SIGUSRl);
else e x i t ( E X I T _ S U C C E S S ) ;
}

,
. ,
. , , signal,
. , SIGUSR1 .

, . , , .
SIGUSR1
raise(SIGUSR1);

.
( . . 4,
signal) .
fptr:
typedef void

(*fptr)(int);

C++

121

signal:
signal (SIGFPE,

(fptr)Handl_SIGFPE);

1.14 Windows
1.14.1 C++Builder

Windows , , (messages). : , ,
Windows, , , , , , .
, , C++Builder , . Windows. ,
C++Builder ,
.
Windows TMessage,
. Msg , . Messages.hpp C++Builder ,
, - .
- - wParam (word
parameter word) IParam (long parameter
long) Result. , C++Builder int.
Word: WParamLo, WParamHi, LParamLo, LParamHi, ResultLo,
ResultHi. "Hi" , "Lo" - .
API Windows C++Builder . , ,
XPos YPos,
IParamLo IParamHi.
Windows . . WM_CLOSE, , .
. , . , .


.
, WM_ACTIVATE.
, . , ,
.
:
WM_ACTIVATE
fActive = LOWORD(wParam);
fMinimized = (BOOL) HIWORD(wParam);
hwndPrevious = (HWND) IParam;

122

*
.
fActive , .
:
WA_ACTIVE

(, Set Active Window ).

WA CLICKACTIVE

WA_INACTIVE

fMinimized , , . .
hwndPrevious , , , , ,
, .
, , .
, .

1.14.2
API Windows , .
1.14.2.1 SendMessage, PostMessage Perform
SendMessage , . PostMessage, .
SendMessage:
Int SendMessage(HWnd hWnd, unsigned int Msg,
WPARAM wParam, LPARAM IParam);

hWnd , .
HWND_BROADCAST,
, , .
Msg . wParam 1ram . ,
, , .
PostMessage :
bool PostMessage(HWND hWnd, unsigned int Msg,
WPARAM wParam, LPARAM IParam);

SendMessage, . , PostMessage
, .
hWnd Msg SendMessage. hWnd = NULL, (
) .
PostMessage .
GetLastError.
, . Perform, :
P e r f o r m ( u n s i g n e d int Msg, WPARAM wParam,

LPARAM IParam);

C++

123

, ,
, C-H-Builder.
1.14.2.2
, . , Forml Form2,
, UlMessl U2Messl , PMessl. Forml , Form2.
#include "U2Messl.h"

Visible Form2 false.


Forml , "Show Form2"
"Close Form2",
Form2->Show();

SendMessage(Form2->Handle,WM_CLOSE, 0 , 0 ) ;

WM_ CLOSE (
SendMessage) Form2. SendMessage
, Handle. WM_CLOSE ; wParam IParam .
:
Form2->Perform(WM_CLOSE,0,0);

.
. ,
Show Form2 Form2,
Close Form2 . Forml .
, ,
Form2 , Windows, Hide. . , Caption " Pmess2" ( )
PMess2, UlMess2. . .
Forml
PMessl. PMessl Forml ,
"Exec Pmess2" "Close Pmess2".

WinExec("Pmess2.exe",SW_RESTORE);

, , PMess2 . . Close
Pmess2
SendMessage(FindWindow("TForml"," P m e s s 2 " ) , W M _ C L O S E , 0 , 0 ) ;

FindWindow
, , SendMessage WM_CLOSE.
. , Exec Pmess2,
PMess2, -

124

. Close Pmess2
PMess2.
.
(TForml) ,
. FindWindow, , . ,
- ? ,
Windows , ,
, ,
WM_CLOSE (, , ).

. (, SciCalc ) WinSight 32 , :
SendMessage(FindWindow ("SciCalc",""),WM_CLOSE,0,0);

1.14.3
Windows . . ,
, .
Windows :
1.
() , .
2. .
3. .
, :
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(parameter!, parameter2, parameters)
END_MESSAGE_MAP

BEGIN_MESSAGE_MAP ,
END_MESSAGE_MAP ,
MESSAGE_HANDLER .
MESSAGE_HANDLER ,
, -.
Windows . , WM_CLOSE. , "". , TWMClose.
,
,
Result, . - , "WM_" "On".
, OnClose.

C++

125

PMess2
Form2 PMessl WM_CLOSE,
Forml. Forml
PMess2 Form.2 PMessl Labell,
, ,
. (
Form2; Forml Form2
Forml):
// U2Messl.h
class TForm2 : public TForm
{

published:
// IDE-managed Components
TLabel *Labell;
private: // User declarations
void
fastcall OnClose(TWMCloseS Message);
public:
// User declarations
fastcall TForm2(TComponent* Owner);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_CLOSE, TWMClose, OnClose)
END_MESSAGE_MAP(TComponent)

};
//

// U2Mess 1. cpp
void
fastcall TForm2::OnClose(TWMCloseS a)
(
Label2->Caption = "! !";
if (MessageDlgPos(" . ?",
mtConfirmation, TMsgDlgButtons() mbYes mbNo mbCancel,
0,BoundsRect.Left,BoundsRect.Bottom) == mrYes)
Close ();
else Label2->Caption = "He !";
a.Result = 0;
}
U2Messl.h public ,
WM_CLOSE. OnClose TWMClose.
private . , message .
OnClose WM_CLOSE ,
, . MessageDlgPos,
, . Close. a.Result = ,
WM_CLOSE.
PMessl.
Show Form2 Form2
Exec Pmess2 PMess2, , Form2
PMess2 , ,
: Close Form2 Close Pmess2, .
.
, .
Close Pmess2 , , ,
, Forml
Close Pmess2. . -

126

, , Close
Pmess2. , , .
, WM_CLOSE . ,
, , . (. 1.14.1) WM_ACTIVA. . , , f Active. WA_INACTIVE , . , .
(Forml Form2 PMessl,
Forml PMess2) WM_ACTIVATE.
, , Label2, .
( Form2):
// U2Messl. h
class TForm2 : public TForm
<
published:
// IDE-managed Components
TLabel *Labell;
TLabel *Label2;
private:
// User declarations
void
fastcall OnClose(TWMCloseS Message);
void
fastcall OnActivate(TWMActivateS Message);
public:
// User declarations
fastcall TForm2(TComponent* Owner);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_CLOSE, TWMClose, OnClose)
MESSAGE_HANDLER(WM_ACTIVATE, TWMActivate, OnActivate)
END_MESSAGE_MAP(TComponent)

};
//

// U2Mess 1.cpp
void
fastcall TForm2::OnActivate(TWMActivateS a)
{
if (a. Active == WA__INACTIVE)
Label2->Caption = " !";
else Label2->Caption = "! !";
a.Result = 0;
}

'

OnActivate , .
Active ,
. .
PMessl.
, , .

1.14.4
, API Windows.
, .

C++

127


WM_USER, .
,
tdefine WM_MyMessl WM_USER
#define WM_MyMess2 WMJJSER + 1

WM_MyMessl WM_MyMess2 Windows, , :


MESSAGE_HANDLER(WM_MyMessl, TMessage, OnMyMessl)

TMessage.
:
struct TMessage
(
unsigned int Msg;
long WParam;
long LParam;
long Result;

};
WParam LParam .
PMessl
Forml CSpinEdit , . PMess2, ,
CSpinEdit.
, UlMessl.h
, , WM_MyPost:
#define WM_MyPost WM_USER


SendMessage(FindWindow("TForml"," Pmess2"),
WM_MyPost,0,CSpinEditl->Value);
! . :
, SendMessage WM_MyPost
WM_USER. .
PMess2.
, :
//

UlMess2.h

f d e f i n e WM_MyPost VWMJSER
/ /
class TForml : public TForm

private:
// User declarations
void
f a s t c a l l OnMyPost(TMessage& Message);
public:
// Wser declarations
f a s t c a l l TForml(TComponent* O w n e r ) ;
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_MyPost, TMessage, OnMyPost)
END MESSAGE MAP(TComponent)

128

1
//

UlMess2.cpp

void
f a s t c a l l T F o r m l : : O n M y P o s t ( T M e s s a g e S a)
{
Label2->Caption = " " + I n t T o S t r ( a . L P a r a m ) ;
}

TMessage Windows.
, . ,
. switch .

C++
, STL, , (. 2.14.7). , STL, . 5.

2.1 ,

, C++Builder, :
Aggregate


Array

struct

union

class

Function

Scalar

Arithmetic

Enumeration

Pointer

Reference

void


. : void, char, int, float double,
short (), long (), signed ( )
unsigned ( ). , unsigned char, unsigned int, signed int ( signed ).
C++ :

char

unsigned char

-128 126
0 255

short

-32 768 32 767

130

unsigned short 2

0 65 535

enum

-2 147 483 648 2 147 483 647

long

-2 147 483 648 2 147 483 647

unsigned long

0 4 294 967 295

int

long

unsigned int

unsigned long

float

3.4 --38 3.4 -1038

double

1.7 --308 1.7-10308

long double

10

3.4 --4932 1.1-104932

bool

true false


int8,
int!6,
int32,
int64,
. . 2.3.
, C++Builder,
C++, bool , . C++. . 0
false, true.
- ,
- , , , , .
, , , , , .
, . , , .

(. . 1.6.1 1.7.1). :
double = 5 . 4 , b = 2;
int ;
void F l ( d o u b l e A ) ;

.
. , (. . 1.8).
:
typedef _ ;

, _ . ,
typedef double A r [ 1 0 ] ;
10 .
. :
= { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 1 0 } ;

typedef , C++. -

C++

131

C++Builder Object Pascal , C++. sysdefs.h. :


typedef
typedef
typedef
typedef

bool Boolean;
int Integer;
short Smallint;
unsigned char Byte;

Delphi (.. Object Pascal) C++.


Delphi

C++

Shortlnt

signed char

typedef

Smallint

16

short

typedef

Longlnt

32

int

typedef

Byte

unsigned char

typedef

Word

16

unsigned short

typedef

Integer

32

int

typedef

Cardinal

32

unsigned int

typedef

Boolean

true/false

bool

typedef

ByteBool

true/false
8

unsigned char

typedef

WordBool

true/false
16

unsigned short

typedef

LongBool

true/false
32

BOOL (WinAPI)

typedef

AnsiChar

char

typedef

WideChar

Unicode

wchar_t

typedef

Char

char

typedef

AnsiString

AnsiString Delphi

AnsiString

Delphi, SmallString<n>
n = 1..255
ShortString Delphi, SmallString<255>
255
AnsiString
AnsiString Delphi
String
float
Single
32
String[n]


typedef
typedef
typedef

Double


64

double

typedef

Extended


80

long double

typedef

Real


32

double

typedef

132

Delphi

C++

Pointer

32

void *

typedef

PChar

32

unsigned char *

typedef

PAnsiChar

ANSI
32

unsigned char *

typedef

Comp


64

Comp

OleVariant

variant OLE

OleVariant

2.2
, , C++Builder
.
: , . ,
. , , ;
, ..
, . .
,
.
. ,
, .
.
double = 5 . 4 , b = 2;
int = * b;

10,
10.8. * ,
, .

!
int m = 1, n =
double A = m /

= 0. , m / n , .

int m = 1;
double n = 2;
double A = m / n;

A = 0.5. double, ,
double, double.
, :
double = 300, b = 200;
short = * b;

C++

133

, , -5536, 60 000. ,
short , 32 767.
60 000,
short .
, -'
. ,
.
()

, .

int m = 1, n = 2;

double A = m / n;

. ,
:
double A = (double)m / n;

,
, double. n double,
, . 0.5.
, : ( . . 1.7.7), . C++Builder 4
TPoint ;
. = 5;

. = 1;

Labell->Caption = " = " + I n t T o S t r ( . ) ;

: "Ambiguity between '_fastcall Sysutils::IntToStr( int64)' and '_fastcall Sysutils::IntToStr(int)'" (


IntToStr
int64 int). ,
, ( )
. ,
int:
Labell->Caption = " = " + IntToStr ( ( i n t ) P . x ) ;
.
C++Builder 6 5
. .
. 2.8.3.
C++ , ,
, ,
. static_cast:
static_cast< > (arg)

arg - , - ,
. , R - , :
// R , (int)R :
static__cast<int> (R)
// R , (AnsiString)R :
static_cast<AnsiString>(R);

134

static_cast , ,
.
X Y (. . 2.8.3).
static_cast
. dynamic_cast,

.
. , ,
. 2.8, 2.9, 2.14. dynamic_cast:
dynamic__cast< > (ptr)

- (. . 2.8) (. . 2.9)
void*, a ptr - , .
void*, ptr . , .
- .
- - : --
ptr , , . :
ptr , , .
- , .
. - ,
, .
dynamic_cast static_cast: . , .
0, Bad_cast.
dynamic_cast .
2.14.6.
. const_cast:
const_cast< T > (arg)

arg const volatile (. . 1.6.2), arg. reinterpret_cas:


reinterpret_cast< T > (arg)

, . , reinterpret_cas . ,
.

2.3
.
char, short, int long
signed unsigned . -

C++

135

.
, .
_

, char signed

char, signed char


unsigned char
char, unsigned char

, char unsigned

signed char
int, signed int
unsigned, unsigned int
short, short int, signed short int
unsigned short, unsigned short int
long, long int, signed long int
unsigned long, unsigned long int
signed unsigned char, short,
int, long. signed unsigned,
signed int unsigned int.
unsigned
signed. char.
C++Builder char signed
unsigned. ,
char ch;

signed char ch;

char ,
:
unsigned char ch;

long short int. long short, long int


short int.
, ,
ANSI . , short, int long , .. short <= int <= long. , . ,
,
.
, C+-HBuilder
32 , . 2.1. , , int long 32 .
: 0 , 1 .
, " int", .
i ui,

136

. , ' .

()

_int8
_int!6
_int32
_int64
unsigned

18

int8 = 12718;
__intl6 s = 32767116;
int32 1 = 123456789132;
_int64 big = 12345654321164;
unsigned int64 hugelnt =
1234567887654321ui64;

116
132
164

int64 ui64

16
32
64
64

float double. 32
, 64. double long, 80 .

C+4-Builder 32
. 2.1. ANSI . , ,
, sizeof (. .
1.9.10, . 1).

2.4
(. . 2.1). , .
C++Builder AnsiChar (char) WideChar (wchar_t). AnsiChar 1 .
. AnsiChar ANSI, , . , . 192 223, - 224 255. "" ( 168 , 184 ). 65 90, 97 122. 48 (0) 57 (1). . 3.1.2
.
char AnsiChar , . . ,
char ch = ' ' ;
Labell->Caption = ch;

"". ch
Labell->Caption = (unsigned c h a r j c h ;

"193" - , "".

Labell->Caption = ( c h a r ) ( c h + 1);

C++

137

"" - , "". .. ch , 1.
.

for (int i = 1; i < 256; i++)


RichEditl->Lines->Add(IntToStr(i) + ' '4 ( c h a r ) i ) ;

RichEditl "193 " . ,


, RichEdit.
ANSI, Windows, , DOS, DOS (
OEM). . 4, . CharToOem
DOS OemToChar, OemToCharBuff DOS , .
WideChar - C++
wchar_t, .
Unicode.
WideChar wchar_t C++Builder 2 ,
. , Linux wchar_t 4 . , Linux GNU
Unicode, .
256 Unicode ANSI.
wchar_t Unicode XML. CLX C++Builder 6 . VCL , MBCS. ,
- , .. . , wchar_t VCL
MBCS.

2.5
2.5.1
C++ . , STL string, . 5. , ('\0').
.
. , , C++ . , . . . 2.11.1,
.
, char*.
char S[] = "";,
char *Sp = "";

. 7 S '', '', '', '', '', ''


'\0'. Sp,
, - .

138

1 .
, . , S[0] Sp[0]
, S[l] Sp[l] ..
. . ,

char b u f f [ 1 0 0 ] ;

buff, 99 .
.
strcat () , strcmp ,
strcpy , strstr
, strlen , strupr , sprintf
.
. 3 4. .
. buff. - ? strcpy:
s t r c p y ( b u f f , " , b u f f " ) ;

, , ,
, .
. , , S1 , S2. strcat:
char SI [ 2 0 ] = " 1", S 2 [ 1 0 ] = " 2";
strcat(S1,S2);

, ,
. , -
.
strcat , , , , . strcat,
. .
, S
S1 S2, .
:
char *S1 = " 1", *S2 = " 2", S [ 2 0 ] ;
strcat(strcat(strcat (S,SI)," " ) , S 2 ) ;

strcat S S1.
S , , strcat ,
S, , . strcat S strcat S2.
, , S
. S,
strcat
strcpy(S,SI)

C++

139

, . , ,
, ..
strstr(SI,S2)

S1 S2 , , .
, .
.
S1 S2 , ,
, S3. , S1 S2 S3.
.
char S l [ 2 0 ] , S 2 [ 2 0 ] , S 3 [ 2 0 ] , S [ 6 0 ] , *St;
// SI, S2, S3
St = s t r s t r ( S I , 3 2 ) ;
if (St)
{
*St = 0;
St += s t r l e n ( S 2 ) ;
Labell->Caption = s t r c a t ( s t r c a t ( s t r c p y ( S , S I ) , S 3 ) , S t ) ;
}
else Labell->Caption = " ";

SI, S2, S3 S, , .
St. .
strstr S2 S1 St.
strstr ( false),
" ". , . , St, 0 . S1,
. St , strlen. St
S1 . S
Labell.
strcat strcpy. strcpy. S
, S1. ,
S1 . strcat
, S, S3.
strcat S1, . St.
, . S1
" ", S2 "", S3 - "". , S1 :
'1,'','','','

','1,'','','

','','','1,'','\0'

strstr St
''. , , S1
:
' ' , ' ' , ' 1 , ' ' , ' ', ' \ 0 ' , ' ' , ' ' , ' ', ' ' , ' ' , '' , ' ' , ' \ 0 '

140

. Pt "". strcpy S
S1, :
'','','','','

','\0'

strcat S S3:
1

'','',' ,'','

','','','' ,'',' ,'\0'

strcat S ,
St, .. S1, "":
1

,'',' ,'','

','','','',' ,'','

','','','','','\0'

sprintf.
Editl,
, CSpinEditl TCSpinEdit,
. " ..., ...
..", :
. :
tinolude <stdio.h>
char S [ 4 0 ] ;
s p r i n t f ( S , " %s, %i r . p . " , E d i t l - > T e x t , C S p i n E d i t l - > V a l u e ) ;

sprintf .
( . . 3, . 3.1.3.1).
, "% ", , sprintf . Editl, %s, ,
CSpinEditl, %i, .

. . 3 4.
C++Builder C++ , .
. AnsiString,
,
, TStrings TStringList. , STL string, . 5.

2.5.2 AnsiString
C++Builder AnsiString , vcl/dstring.h Delphi. . AnsiString .
AnsiString ==, !=, >, <, >=, <=. . , , , , , . ,
, , .
AnsiString =, += () +. []. 1. , S1 = "", Sl[l] '', Sl[2] '' ..

C++

141

AnsiString , .
3.1.6. , AnsiString.
AnsiString C++Builder. , , Text , Caption ..
TStrings. ,
, AnsiString.
AnsiString.
() :
Labell->Caption = Editl->Text + ' ' + Edit2->Text;

Labell->Caption ,
Editl, ,
, Edit2.
, AnsiString "+".
sir cat,
(char *), AnsiString.

S1 , S2, S3.
, , :
A n s i S t r i n g SI, S2, S3;
// SI, S2, S3
int i = S I . P o s ( 3 2 ) ;
if (i)
Labell->Caption = S I . S u b s t r i n g ( 1 , i - 1 ) + S3 +
SI.SubString(i+S2.Length(),255) ;
else Labell->Caption = " ";

- AnsiString: Pos,
Substring, Length. ,
(.), C++Builder (>). ,
, AnsiString .
Pos.
, ( S1), , ( S2). , . 1. , 0.
if...else ,
(false) Pos . , .
: S1, , S3, , S1, . S1 Substring.
, , , , ,
. , Sl.SubString(l, i 1) S1, i 1 , .. S1, S2. , Sl.SubString(i +

142

S2.Length(), 255) S1, S2.


Length, (
S2, ). Substring 255, , , . 255 , , S1 .

(char *), ,
AnsiString.
,
S1, ,
:
int i = SI.Pos ( S 2 ) ;
SI = S I . S u b s t r i n g ! ! , i - 1 ) + S3 + S I . S u b s t r i n g ( i + S 2 . L e n g t h ( ) , 2 5 5 ) ;

(char *)

.
: S1 S2 S3. :
int id = 0, i = S l . P o s ( S 2 ) ;
while ( i )

SI = S l . S u b S t r i n g d , i -I- iO - 1) + S3 +
SI.Substring (i + iO + S 2 . L e n g t h ( ) , 2 5 5 ) ;
iO += i - 1 + S3.Length ( ) ;
i = S l . S u b S t r i n g ( i O + 1, 255) .Pos ( S 2 ) ;

- . . -,
10 , S1. . -, S2 S1
S1, : Sl.SubString(iO + 1,
255).

, Delete Insert AnsiString.
Delete , , , , .
Insert , , , .
, , :
int 10 = 1, i = S l . P o s ( S 2 ) ;
while(i > iO)
{
SI.Delete(i,32.Length());
// S2
SI. Insert(S3,i);
// S3
iO = i + S3.Length();
i = iO - 1 + S I . S u b s t r i n g ( i O , 255) . P o s ( S 2 ) ;
}

,
AnsiString. -

C++

143

. 3.1.6. ,
AnsiString (char *). , AnsiString (char *),
, (char *).
API Windows C++Builder, . , Application>MessageBox, ( ) (char *).
PlaySound .
AnsiString (char *) c_str() , , AnsiString, . ,
S1 S2 AnsiString,
Application>MessageBox ,
Application>MessageBox :
Application->MessageBox(Sl. c_str ,52.c_str(), _);

(char *) AnsiString.

AnsiString(char *S)

AnsiString, ,
S, .

2.6
,
.
, . ,
C-H-Builder , ,
, .
, . , , Mode,
:
, , . , ,
Mode int '
: 0 , 1 , 2
.
if (Mode == 1)

...

, Mode, 1,
. : Mode mRead, mEdit, mWrite.
:
if (Mode == mEdit) . . .
, , .
:
enum {< 1>,

. . . , < >} < >;

enum {mRead, mEdit, mWrite} Mode;

144

mRead, mEdit, mWrite Mode, . , mRead. . :


Mode = mEdit;

, . , , : >, < .. , :
if(Mode > mRead) . . . ;
if(Mode < m W r i t e ) . ..;
if(Mode == mEdit)

Mode switch:
switch (Mode)
{
case mRead:

break;

case mEdit:
case mWrite:

break;
...

, enum, , 0, 1 .. >, <


. , (=) , , . :
enum {mRead = -1, mEdit, mWrite = 2} Mode;

- , 1
. mRead 1,
mEdit 0, mWrite 2.
enum .
:
enum regim {mRead = -1, mEdit, mWrite = 2} Mode, Model;

Mode Model ,
regim. regim - , :
regim Mode3;

2.7
, , ,
. , .
+-!-Builder , vcl/sysdefs.h.
:
Set <type, minval, maxval> ;

C++

145

type .
int, char . minval maxval unsigned
char .
0, 255.
.
si
:
Set <char,

'A',

' Z ' > si;

Ch, :
Set <char, 0, 255> Ch;

UPPERCASESet s2 s3 :
typedef Set <char, ' A ' , ' Z ' > UPPERCASESet;
UPPERCASESet si, s2;

S, : red, yellow, green:


enum E { white, red, yellow, green };
Set <E, red, green> S;

Set -
. .
( ):

Set

fast call operator


-(const Set& rhs) const; :
rhs ( )

Set&

fastcall operator
=(const Set& rhs);

,

: rhs ( )

Set&

fastcall operator
*=(const Set& rhs);

,

: rhs
( and )

*k

Set

fastcall operator
*(const Set& rhs) const; :
rhs ( and )

Set

+=

,
fastcall operator
+(const Set& rhs) const;
: rhs
( )

Set&

fastcall operator +=(


const Set& rhs);

:
rhs ( )

146

Set&
fastcall operator
(const T el);

friend ostream& operator (


ostream& os, const Set& arg);

Set&

el

arg
ostream ( 0 1

)

el

arg
istream ( 0 1

)
fastcall operator =(coiist rhs
Set& rhs);
fastcall operator ==(const :
rhs (
Set& rhs) const;
)

fastcall operator
(const el);
friend istream& operator
(istream& is, Set& arg);

Set&

bool

!=

bool

fastcall operator !=(const


Set& rhs) const ;

: rhs

,
, (type, minval
maxval) . , ( +, *),
, , ,
. true , . false.
Set :

Clear
Contains

Set&
bool

fastcall ClearQ;

fastcall Contains(const el) const;
el

.
, "Yes/No". , , , "", "Y", "" "N".
:
Set <char, 0, 255> TrueKey;
' ' ' ' ' n 1 ' N ' ;

, Key , Contains:
if (ITrueKey.Contains(Key))
ShowMessge(" ");
else . . .

C++

147

. ,
Editl , .. 0 9.
, OnKeyPress :
Set <char, ' 0 ' , ' 9 ' > Dig;
Dig ' 0 ' '!' ' 2 ' ' 3 ' ' 4 ' ' 5 '
'6' '7' '8' '9';
if ( ! D i g . C o n t a i n s ( K e y ) )
{Key = 0; BeepO ; }

, ,
( ) .

2.8
2.8.1
, , .
, .
.
, ,
. :
type *ptr;

type ,
ptr . : ptr type.
,
int *countPtr, count;

countPtr int * (.. ) count . * countPtr.


, ,
(*). , count
, :
int *countPtr, *count;
* .
void:
void *Pv;

. , , -
. :
Pv = countPtr;

,
. , NULL . 0
NULL . NULL , , .
:
int *countPtr = NULL;

, NULL . , .

148

(&), . ,

int = 5;
int *yPtr, ;


yPtr = &;

yPtr.
, , (*), . ,
(.. ). , ,

= *yPtr

5, .. , yPtr.
void,
, .
C++
. . ,
.
,
. :
int b [ 5 ] = ( 1 , 2 , 3 , 4 , 5 } , *Pt;

[5] Pt. ,
Pt b
Pt = b;

Pt = s b [ 0 ] ;

[3]
*(Pt + 3).
, . , Pt[3] [3].
, ,
.
.
,
. ,
, .

. (++), (), (+ +=), ( =) .
.
1 ,
, .

C++

149

. ,
Pt b ,

Pt += 2;

Pt . Pt , , 2. , b 2 , Pt (.. , Pt) 4.
.
. , Pt
, Ptl ,
Ptl Pt 2 ,
. , , ,
, 4 ( 2 ).
,
. ,
, . >, <, >=, <=
. == !=
. ,
.
,
.
,
. void (.. void*), , . void
. void
void
.
.
.
.
, :
char *Sa[2] = (" ", ""};

2 (char *). . C++ , ,


. , . , .
. , .
. . . 1.7.2.

2.8.2
C++Builder . , , .. , (. . 2.14). , :

150

2
TForml *Forml;
TLabel *Labell;

Forml (Labell). , - . ,
TLabel ():
TLabel *Lab;

, .
. . ,
, , , , :
i f (Lab = = 0 )

... ;

, .
C++ NULL, . :
if

(Lab

==

NULL)

Lab
. :
Lab = L a b e l l ;

Lab Labell. : Lab, Labell . , Labell >Caption Lab>Caption .


, , void.
:
void *Lab;

void
. . , ,
. , , Labell (
) Lab>Caption. Caption
((TLabel *)Lab)>Caption, Lab TLabel.

, , .
,
, -.
.
, ,
, , .. C++
.
, TControl :
TControl *Contr/

. ,
Contr = Labell;

C++

151

.
Con.tr . ,
TControl. , , , Name .
. , Contr>Caption
: 'Controls:: TControl "Caption' is not accessible. ,
, Caption TControl . ,
TControl, , :
((TLabel *)Contr)->Caption
: Contr
TLabel. .
, ,
.
.

2.8.3

, , -. +-t-Builder . , Sender , .
? , - , , Button!
OnClick, , Sender
. ,
Buttonl.
. . .
, , .
C++Builder
Sender, TObject *Sender, ..
TObject. TObject C++Builder.
,
. -
Sender
, . , , , ( Caption) Labell
: " ...". ,
, Name. TComponent. ,
Sender ( . . 2.2). :
Labell->Caption = " " +
((TComponent *)Sender)->Name;

152

((TComponent *)Sender)
Sender TComponent.
Name, . : , , .., TComponent.

. 2.2 static_cast:
Labell->Caption = " " +
static_cast<TComponent
*>(Sender)->Name;


, Sender , . , , :
TComponent *0bj = (TComponent *)Sender;
Labell->Caption="npoM3Ourno " + Obj->Name;

Obj TComponent
, Sender. Obj .
, Sender ,
-,
, . ,
, Sender, TWinControl ( ), TWinControl ScaleBy.
:
( (TWinControl * ) S e n d e r ) - > S c a l e B y ( 1 1 , 1 0 ) ;

,
Sender. ClassName,
TObject
ShortString

fastcall ClassName();

ClassName ShortString, . ,
Labell->Caption = Sender->ClassName() ;

"TButton", Sender TButton.


ClassName -
. ,
if

(String(Sender->ClassName())

== "TLabel")

( )
TLabel.
ClassNamels,
TObject :
bool

fastcall ClassNamels(const AnsiString string);

true, string. :

C++
if

153

(Sender->ClassNameIs("TLabel"))

, -,
. ScaleBy, TWinControl. , Sender, TWinControl (, TLabel, TWinControl),
ScaleBy .
, , .
, ,
, ,
, . , , ScaleBy, ,
TWinControl.
InheritsFrom,
TObject , , .
:
bool

fastcall

InheritsFrom(TClass aClass);

true,
aClass, . TClass,
classid:
classid(classType)

, , TWinControl.
, , ,
Sender, TWinControl, :
if

(Sender->InheritsFrom(

classid(TWinControl)))

ScaleBy
:
if

(Sender->InheritsFrom( c l a s s i d ( T W i n C o n t r o l ) ) )
((TWinControl *)Sender)->ScaleBy(11,10) ;

ClassParent, TObject,
, .
:
TClass

fastcall

ClassParent()

(.. TObject), NULL.


ClassParent, , . ,
, TObject , Sender.
TClass ClassRef= Sender->ClassType();
ListBoxl->Clear();
w h i l e ( C l a s s R e f != NULL)
ListBoxl->Items->Add(ClassRef->ClassName() ) ;
ClassRef = C l a s s R e f - > C l a s s P a r e n t ( ) ;

154

, Sender TButton, ListBoxl :


TButton
TButtonControl
. TWinControl
TControl
TComponent
TPersistent
TObject

2.9
, . , (&) ,
. -
MyObject:
MyObject *P = new MyObject;
:
MyObject & Ref = *;

Ref
MyObject. . , .
. ,
,
>, .. .
Ref.x, .. .
. , Labell, Caption
Labell->Caption = " ";
:
TLabel & ref = *Labell;
ref.Caption = " ";

. . 1.7.2.

2.10
C++Builder ( ) :


++
.

2.10.1 /

LoadFromFile SaveToFile, TStrings TStringList.

C++

155

,
.
, , . :
TStringList, ,
AnsiString, . :
TStringList *List = new T S t r i n g L i s t ;
AnsiString SFile = "Test.txt";

He , ,
(. . 1.5.1). , "c:\MyTest\Test.txt", ":\\MyTest\\Test.txt".
, ,
List->LoadFromFile(SFile);

, , ,
. ,
. :
try{
List->LoadFromFile(SFile);
}
catch(.. . ) {
ShowMessage(" \ " " + SFile + " \ " " ) ;
}

List, . Strings[int Index],


AnsiString. .
List->Strings[0] , List->Strings[l] ..
TStringList . , AnsiString (. . 2.5.2 . 3).
,

List->SaveToFile(SFile);

SFile .

Windows, ++ilder.
, ,
- ,
TStringList. TRichEdit.
,
RTF. Lines
TStrings, LoadFromFile SaveToFile. :
Memol->Lines->LoadFromFile(SFile);
RichEditl->Lines->LoadFromFile(SFile);

C++Builder , .

156

2.10.2 /
2.10.2.1
C++ (stream),
. , .
.
, , ,
() FILE, stdio.h.
fopen,
FILE.
.
fopen:
#include <stdio.h>
FILE * f o p e n ( c o n s t char *filename, const char *mode);

fopen ,
filename, . mode ,
. :

W+

"+" "t" , "" , . , rt, rb, r+t, +b .. "t", "" ,


_fmode,
fcntl.h. _ ( ) O_BINARY . . 3, . 3.5.2.
fopen , ..
, " , .
. . 3, . 3.5.2
, .
fopen , .
, fopen .
, ( ) ,
fclose(FILE *), .
2.10.2.2
. Test.txt :

C++

157

#include < s t d i o . h >


FILE *F;
if ((F = fopenC'Test.txt", "rt")) == NOLL)
{
ShowMessage(" ");
return;
}

...

fclose(F) ;

//

//

F
Test.txt, .
(, ), .
. fclose(F).

fopenC'Test.txt", "rt+")

,
.
.
fgets:
char * f g e t s ( c h a r *s,

int n,

FILE * s t r e a m ) ;

s , , n . "\" ( ),
n 1 . .
, Memol :
char s [80] ;
Memol->Clear ( ) ;
do
{
f g e t s ( s , 8 0 , F) ;
i f ( f e o f ( F ) ) break;
i f ( s [ s t r l e n ( s ) - l ] == ' \ n ' ) s [ s t r l e n ( s ) - l ] = 0;
Memol->Lines->Add(s);
}
while(true);
fclose(F);
//

fgets . feof , . feof


. ,
i f ( s [strlen ( s ) - 1 ] = = ' \ n ' ) s [ s t r l e n ( s ) - 1 ] = 0 ;

,
. , "\" Memol. .

fscanf.
int f s c a n f ( F I L E *stream,

const char * f o r m a t [ ,

address,

...]);

format ,
. . 3, .
3.1.3.2. , "%",

158

. ( . . 3.1.3.2):

i
I
d
D
u

e, E
s


,
,






int *arg
long *arg
int *arg
long *arg
unsigned int *arg
unsigned long *arg
float *arg
char arg[]
char *arg

. , 1 long int, double.


, , , , , , , .
:
int 11, 12;
double r;
fscanf(F,

&i2, &r)

, ,
fscanf , , . (&) ,
.
- - . , , , fscanf.
. :
if ( f s c a n f (F, "%d%d%le", & i l , &12,
{
ShowMessage ( " " ) ;

&r)

!= 3)

s , -- ,
. , , , , , Editl.
, , , , :
char s [80] , key [10] ;
strcpy ( k e y , E d i t l - > T e x t . c _ s t r ( ) ) ;
do

f s c a n f (F, "%s", & s ) ;

//

C++

159

i f ( f e o f ( F ) | | ! s t r c m p ( s , k e y ) ) break;
}
while(true);
fclose(F);
if ( ! s t r c m p ( s , k e y ) )
ShowMessage(" ");

s key,
strcpy . fscanf s . strcmp . 0, s key . ,
.
.
. fprintf:
int f p r i n t f ( F I L E *stream, const char * f o r m a t [ , argument,

...]);

fscanf,
. , "%".
. ,
, "%", . fprintf . 3 4. .
s (char *), ,
year, .
, , ..., ... ...
. :
FILE *F;
if ( ( F = fopen ( " T e s t . t x t " , " w t " ) ) == NULL)

ShowMessage(" " ) ;
return;

}
char S [ 4 0 ] ;
int year = 1960;
strcpy(s,"") ;
f p r i n t f ( F , "\ %s, %i r . p . \ n " , &S, year);
fclose(F);

fopen . , . , . fprintf
. ,
"\"; - " ", "%s", S, "%i", year,
. :

, 1960 . .

. . 3 4.

160

2.10.2.3
,
- , ..
, .
, .
.

- . , ,
: . ,
, ,
.
, . ,
- , , , .
, , .
2.10.2.1. fwrite freed:
#include <stdio.h>
size_t fwrite(const void *ptr, size_t size, size_t n, FILE *stream);
size_t f r e a d ( v o i d *ptr, size_t size, size_t n, FILE * s t r e a m ) ;

ptr .
size , n .
.
int i = 1, j = 25, il, j l ;

double a = 25e6, al;


char s[10], si [10];
strcpy(s,"");

FILE *F;
//
if ( (F = fopen("Test.dat", "wb")) == NULL)
{
ShowMessage(" ");
return;
}
fwrite(&i,sizeof(int),1,F);
//
fwrite(&j,sizeof(int),1,F);
//
fwrite(&a,sizeof(double),1,F);
//
fwrite(s,sizeof (char),strlen(s)+1,F); //
fclose (F);

i
j
a
s

//
if ((F = fopen ("Test.dat", "rb")) == NULL)
{
ShowMessage(" ");
return;
}
fread(&il,sizeof(int),1,F);
//
fread(Sjl,sizeof(int),1,F);
//
fread(sal,sizeof(double),1,F);
//
fread(sl,sizeof(char),strlen(s)+1,F); //
fclose (F);

i
j

C++

161

"Test.dat"
i j, s. ,
, il, jl, al si,
, , .
.

fwrite ( s , s i z e o f ( c h a r ) , s t r l e n ( s ) + 1 , F ) ;

// s

strlen(s)+l ( ).
:
f r e a d ( s l , s i z e o f ( c h a r ) , s t r l e n ( s ) + 1 , F ) ; // s

strlen(s)+l .
.
, , . , , , ?
.
:
fwrite(s,sizeof(s),1,F) ;
fread(si,sizeof(s),1,F) ;

, :
s, .

fwrite(s,sizeof(char)*10,1,F);
fread(si,sizeof(char)*10,1,F);

,
. ,
, .
- , ,
. :
//
fwrite(s,sizeof(char),strlen(s)+1,F);

//

f o r ( i n t ind = 0; ind < 10; ind++)


(
fread(sl+ind,sizeof(char),1,F);
i f ( s i [ i n d ] == ' \ 0 ' ) break;
)

for . ,
sl+ind. sl[ind], fread
, , .
fread fgetc, :
si[ind] = fgetc (F);

, ,
. , . :

162

2
//
int it = strlen (s)-t-1;
fwrite (Sit,sizeof(int), 1,F);
fwrite(s,sizeof (char),it,F);
...
//
fread(Sit,sizeof(int) , 1, F) ;
fread(si,sizeof (char), it, F) ;

. ,
, . () , . .
ftell, :
long int ftell(FILE *stream);

fseek:
int fseek(FILE *stream,

long o f f s e t ,

int whence);

offset ,
whence. whence :

whence

SEEK_SET

SEEK_CUR

SEEK_END

whence = 1, offset (
) ( ).
rewind ( 0). ,
f s e e k f F , OL, 0 ) ;

, . , double, , i-oe
,
fseek(F, sizeof(double)* (i-1), 0 ) ;
f r e a d ( & a , s i z e o f ( d o u b l e ) , 1, F) ;

.
.
, , , , , 10. ,
(, "rb+"), , ,
:
fread(&a,sizeof(double), 1,F);
a *= 10;
fseek(F,-sizeof(double),1);
fwrite(Sa,sizeof(double),1,F);

,
10. , fread .
, , .
:

C++
long int pos = ftell(F);
fread(Sa,sizeof(double), 1, F) ;
a *= 10;
fseek(F,pos,0);
fwrite(&a,sizeof(double),1,F);

163
//
//

ftell , , fseek .

, , , . , spers, pers persl, pers , . , ,
, persl.
struct spers
{
char N a m e [ 2 0 ] ;
int year;

};

struct spers pers, persl;


strcpy(pers.Name,"");
pers.year = I960;
FILE *F;
if ((F = fopen("Test2.dat", "wb")) == NULL)
{
ShowMessage(" ");
return;
}
fwrite(&pers,sizeof(spers), 1,F) ;
fclose(F);
if ((F = fopen("Test2.dat", "rb")> == NULL)
{
ShowMessage(" ");
return;
}
freadf&persl,sizeof(spers),1,F);
fclose(F);

2.10.2.4 /,
,
FILE, . , , .

:

stdin
stdout

stderr

.
, , io.h. stdio.h, fcntl.h, sys\types.h
sys\stst.h.

164

open, :
#include < f c n t l . h >
#include<io. h>
int open (const char *path,

int access, unsigned m o d e ) ;

path . access . mode


.
access (|) . ( . . 3, . 3.5.1):
O_RDONLY
0_WRONLY
RDWR
CREAT
OJTRUNC
O_BINARY
_





, 0

mode :
S_IWRITE
S_IREAD
S_IREAD | S_IWRITE

,
int handle;
if ( (handle

open ("Test.txt", 0__CREAT | _) ) == -1)

ShowMessage (" ");


return;

, ( open -1) .
_creat, ,
open.
close:
int close (int h a n d l e ) ;

, handle, write read:


#include <io.h>
int w r i t e (int handle, void * b u f , unsigned len) ;
int read (int handle, void * b u f , unsigned l e n ) ;

buf ,
len .
, , , . 2.10.2.3, i j,
s:

165

C++
#include <stdio.h>
tinclude <stdlib.h>
ttinclude <fcntl.h>
tinclude <sys\stat.h>
tinclude <io.h>
tinclude <string.h>

int i = I,- j = 25, il, jl;


double a = 25e6, ;
char s[10], sl[10] ;
strcpy(s,"");
int handle;
//
if ((handle = open ("Test.txt", 0 WRONLY | 0 GREAT I 0 BINARY))
== -1)
ShowMessage(" ");
return;
write(handle, &i, sizeof (int));
write (handle, &j, sizeof (int));
write(handle, &a, sizeof(double));
write(handle, s, strlen(s)+1);
close(handle);
//
if ((handle = open ("Test.txt", 0 RDONLY

//
//
//
//

i
j

BINARY)) == -1)

ShowMessage(" ");
return;
}
read (handle, si-1, sizeof (int) );
//
read(handle, &jl, sizeof (int));
//
read(handle, &al, sizeof(double));
//
read(handle, si, strlen (s)+1);
//
close(handle);

i
j

, . 2.10.2.3,
, . , , . 2.10.2.3, .
, , tell Iseek, . 2.10.2.3 ftell
fseek, .
dup dup2, , , ,
. . 3, . 3.5.3, 3.5.4.

2.10.3 / C++
2.10.3.1
C++ /:
ifstream
ofstream
fstream

166

,
#include <fstream.h>

, , ,
()
().
, , . ,
ofstream outfile ( " T e s t . d a t " ) ;
if(!outfile)
{
ShowMessage(" ");
return;

outfile, "Test.dat", , , .
- , outfile
if .
, :
if stream i n f i l e ( " T e s t . d a t " ) ;
if ( ! i n f i l e )
{
ShowMessage (" ");
return;


() (), . 1.9.15. , ,
. , ,
:
int i = 1, j = 25, il, j l ;
double a = 25e6, al;
char s [40] , si [40] ;
strcpy (s, "") ;
//
ofstream o u t f i l e ("Test .dat") ;
if ( ! outfile)
{
ShowMessage (" ");
return;
)
o u t f i l e i ' ' j ' ' a ' ' s endl;
//
o u t f i l e . close ( ) ;
//
ifstream i n f i l e ( "Test . dat") ;
if ( ! i n f i l e )
(
ShowMessage (" ");
return;
}
i n f i l e il jl al s i ;

C++

167

//
infile.close() ;

"Test.dat"
i j, s, ,
endl (. . 1.9.15)
. , , . , , .
, , "1 25 2.5+07 ". ,
,
.
. 1,
. 1.9.15. , ,
. 2.10.3.2.
: put write.
put . ,
outfile.put('1);

"". put . ,
outfile.put('') .put('\') ;

"" .
write ,
, , . ,

o u t f i l e . w r i t e ( s , 5) ;

outfile 5 s.
, .
, , ,
.
read - . gcount
, .
.
() , . ,
. , ,
. ,
- . ,
.
ifstream : get getline. get : get(), get(char) get(char *, int n, char delim).
get
(, )
. get EOF, .
get , :

168

2
char s [80], ;
ifstream inflie("Test.dat") ;
if (linfile)
{
ShowMessage(" ");
return;
}
int i = 0;
while(( = infile.get()) != EOF)
(
if (c == '\n')
{
//
s[i] = 0;
//

i = 0;
}
//
else s[i++] = ;
}
//
inflie.close();

.
"\", s. "\",
, - , . , : ,
. , .
get() -
. , "$" :
while(( = infile.get ()) != EOF)
if( == '$') break;
if ( =*= '$') ...

- get (, ) . get ,
; get
, - get.
get
,
while:
while(infile.get(c))

- get :
s, delim (
'\').
, , 1 , .
, , . , ( ).
, get
, .

C++

169


:
char s [80] ;
if stream inf ile ("Test .dat") ,
if (! inf ile)
{
ShowMessage (" ");
return;
}
while(!infile.eof() )
(
inf ile. get (s, 80) ;
inf ile .get () ;
//
}
//
inf ile. close () ;

get . "\" get


(, 80 ). ,

infile.get (s, 80) ;

inf ile .get ( ) ;

. , .
*,>
get , * ,
. getline. get . get getline (.. );
.
getline :
while ( '.infile.eof () )
{

inf ile. get line (s, 80) ;


//

2.10.3.2
. 2.10.3.1 . 1 . 1.9.14
endl, .
, .
, ,
Memol , OnClick :
tinclude <fstream.h>
tinclude <iomanip.h>
char s [40] ;

170

2
//
ofstream outfile("Test.dat");
if('outfile)
{
ShowMessage(" ");
return;
}
// ,
//
outfile.close();
ifstream infile("Test.dat");
if(!infile)
{
ShowMessage(" ");
return;
}
Memol->Clear() ;
while(!infile.eof())
{

infile.getline(s,80);
Memol->Lines->Add(s);

>

//
infile.close();

dec, oct, hex setbase , , , .


. ,
, ,
. setbase . .
<iomanip.h>. .
int i = 31;

o u t f i l e i ' ' hex i ' ' oct i ' '


setbase (10) i endl;

"31 If 37 31". 31 , , ,
.
, .. , setprecision precision.
, .
,
:
f o r ( i n t i = 0; i < 10; i + + )
o u t f i l e s e t p r e c i s i o n ( i ) s q r t ( 3 . 0 ) endl;

setprecision 0 9
3.
0 , 6. :

C++

171

1.73205

1.73
1.732
1.7321
1.73205
1.732051
1.7320508
1.73205081

, precision:
f o r ( i n t i = 0; i < 10;

outf lie .precision (i) ;


outfile s q r t ( 3 . 0 ) endl;
}

precision , ,
int i = outf ile. precision ( ) ;

.
setw width (..
, , , ) . , ,
. , .. .
, , .
; 0, .. , . width, , .
setfill(char)
fill.
,
25:
int j = 2 5 ;
f o r ( i n t i = 0; i < 5; i++)

o u t f i l e s e t w ( i ) j endl;

:
25
25
25
25
25

,
, , .
, width:
f o r (int i = 0; i < 5; i++)
{
out f i l e . width (i) ;

o u t f i l e j endl;

172

setfill, . ,
f o r f i n t i = 0; i < 5; i++)
outfile s e t f i l l C * ' ) s e t w ( i ) j endl;

:
25
25
25
*25
**25

( ) .
. ,
, , ,
tab, "\t".
// tab
ostreams tab (ostreams output)
{
return output ' \ t ' ;
}

, . ,
outfile ' ' tab ' ' tab ' 1 endl;
"", "" "", :

2.10.3.3
ios / .
ios:: skip ws

ios::left
ios::right

ios::internal

ios:: dec

, dec
, oct
, hex

ios::oct
ios::hex

ios::showbase
ios::showpoint

ios::uppercase

"X" ""

C++

173

ios::showpos

"+"

ios::scientific

ios::fived

flags, setf unsetf, setw, setiosflags resetiosflags.


flags . ,
,
(|) long, . flags long, . ,
flags .
setf setiosflags , ,
|, . ,
setiosflags (ios::showpos I ios::showpoint)
ios::showpos ios::showpoint.
resetiosflags unsetf , ,
. , #include <iomanip.h>.
.
, showpoint:
o u t f i l e 1. " " 1.1 " "
s e t i o s f l a g s ( i o s : : s h o w p o i n t ) 1. "

" 1.1 endl;

:
1

1.1

1.00000

1.10000

, right, left internal:


outfile

setw(6) -1.1 endl


s e t w ( 6 ) resetiosflags(ios::right)
setiosflags (ios :-.left) -1.1 endl
setw(6) resetiosflags(ios::left)
s e t i o s f l a g s ( i o s : : i n t e r n a l ) -1.1 endl;

:
-1.1
-1.1
- 1.1
, resetiosflags
, right,
left internal .
, showbase:
o u t f i l e 63 oct " " 63 hex " " 63
setiosflags ( i o s : : s h o w b a s e ) dec endl
63 oct " " 63 hex " " 63 endl;

:
63 77 3f
63 077 Ox3f

174

, setiosflags, dec, oct, hex.


, scientific fixed:
outfile

" :" endl


0.0123 ' ' 1 . 2 3 endl endl
" s c i e n t i f i c : " s e t i o s f l a g s ( i o s : : s c i e n t i f i c )
endl

0.0123 ' ' 1.23e6 endl endl


" fixed:" resetiosflags(ios::scientific)
setiosflags(ios::fixed) endl
0.0123 ' ' 1.23e6 endl;

:
:
0.0123 1.23-
scientific:
1.230000-02 1 .230000+06
fixed:
0.012300 1230000.000000
,
, , .
, showpos showpoint:
o u t f i l e s e t p r e c i s i o n ( 4 ) s e t w ( 3 ) 6 0 . endl
setiosflags (ios::showpos I ios::showpoint) 60.
endl;

:
60
+60.00

setiosflags .

2.11
2.11.1
, , - . , , (
), .
, .. 1.
:
[_]
,
int A[10];

, 10 .
A[i], i -- ,
, , 0-9. , [0] , [1] , [9] .
, 1 .
, 0.
.

C++

175

[ 0 ] = 1;
[1] = 1;

f o r ( i n t i=2; i < 10; i++) A [ i ] = A[i-2 ] +A[i-l] ;

, 2
1, .
. ,
char S[10] ;

.

(. . 2.5.1) ,
.
, .
, , - 1, .
.
, .
:
int [10] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 1 0 } ;
char S[10] = ("abcdefghi\0") ;

, , . ,
int A [10] = (1,2,3);
, 0.
int [10] = ( 0 } ;

.
,
. , - .
, , , .
S . . ,
:
char S[10] = ("abcdefghi"} ;
char SI [10] = {"abc"};

10 , .
. . ,
int [ ] = (1, 2, 3, 4, 5) ;

.
char Sl[ ] = ("abc"};

.
. , ,
:

176

2
int
//
//
int Sum = A[0] ;
for (int i = 1; i < 10; i++) Sum += A[i];

, 10 ,
, , 100,
, , ( for).
. , .
:
const Amax = 10;
int A [Amax] ;
//
//
int Sum = A[0] ;
for (int i = 1; i < Amax; i++) Sum += A[i];

Amax
, . , Amax. . Amax , - .
, #define (. . 1, . 1.4.2).
fdefine Amax 10

, . .
, .
. :
const AnsiString Day[] = {"", "", "",
"", "", "",
"" } ;

2.11.2
, .. ,
. , :
int A2[10] [3];

,
, 10 3 .

, . ,
2[3][2] - - ,
(, 0).
, .
A3 4 3 2.

C++

177

int 3[4][3] [2] = { { { 0 , 1 } , { 2 , 3 } , { 4 , 5 } } ,


1(6,7},(8,9},(10,11}},
({12,13),(14,15),(16,17}},
{{18,19},{20,21},(22,23}}};

A3,

, 3[0][1][0] 2, 3[3][0][1] 19 ..
- ,
.

2.11.3 ,

.
. 2.8.
, ,
.
sizeof,
, , . ,
sizeof() / sizeof([0])

.
ARRAYSIZE.
ARRAYSIZE()

. , F , :
void F (int A r [ ] ) ;

:
const Amax = 10;
int A[Amax];
F (A) ;

, . , ,
[2]. C++ (. . 1, . 1.7.2).
, ,
, .
, . ,
.
, .
:

178

2
void F f i n t Ar[], int N) ;

:
F (A, Amax) ;


, , .
:
F(A, Amax - 1) ;

, Object Pascal,
. , sysdefs.h EXISTINGARRAY, . :
F(EXISTINGARRAY(A)) ;

EXISTINGARRAY .

sizeof.
Object Pascal, C-H-Builder, ,
. sysdefs.h
OPENARRAY, . :
OPENARRAY(TVarRec,

(^!, _2,

...))

19.

.
, :
void F (const int A r [ ] , int N) ;

, , , . :
int Sum(const int A [ ] ,
I
// N

int N)

int S = A[0];

for (int i = 1; i < N; i + + ) S += A [ i ] ;

return S;
)

.
^define Bmax 10
int BflO] = {1,2,3,4,5,6,7,8,9,10};
ShowMessage(" " + IntToStr(Sum(,Bmax)));

.
- . ,
, .
Bmax, a Bmax - 2,
0 7.
- . , :
Sum( + 2, Bmax - 2)

C++

179

, . , 0 7,
, 2 9. .. , .
, , . , F2 3 3, :
void F(const int A r [ ] [ 3 ] ) ;

.
, F(A).

2.12
2.12.1
, .
. , ,
, .
. , .
:
struct TPers {
AnsiString F a m , N a m , P a r ;
unsigned
Year;
bool
Sex;
A n s i S t r i n g Dep;

struct .
TPers (, -) .
.
TPers. , . , . .
TPers . ,
.
: Fam, Nam, Par Dep , , , , . Year , Sex . ,
. , TPers
TPers.
TPers. , , , .
(. . 2.12.2).

180


; ,
. , .
TPers Pers, PersArray[10], *Ppers;

Pers TPers, PersArray 10


TPers Ppers TPers.

.
:
struct {
AnsiString Fam,Nam,Par;
unsigned
Year;
bool
Sex;
AnsiString Dep;
}Pers, PersArray[10], *Ppers;

: (.) (->).
. :
Pers.Fam = "";
Pers.Nam = "";
Pers.Par = "";
Pers.Year = 1960;
Pers.Sex = true;

Pers.Dep = "";


. ,
Ppers = &Pers;
Ppers Pers.
:
Ppers->Fam = "";
Ppers->Nam = "";
Ppers->Par = "";
Ppers->Year = 1960;
Ppers->Sex = true;
Ppers->Dep = "";

2.12.2
. (. . 1, . 1.11) , ,
. , , .
. . NULL,
.

C++

181

N NULL

. 2.1.

, . 2.12.1, , :
struct TPers {
AnsiString Fam,Nam,Par;
unsigned
Year;
bool
Sex;
AnsiString Dep;
TPers * pr;

.
, :
TPers *PO = NULL, *Pnew, *Pold;


. . , :
//
Pnew = new TPers;

//
Pnew->Fam = "";
Pnew->Nam = "";
Pnew->Par = "";
Pnew->Year = I960;
Pnew->Sex = true;
Pnew ->Dep = "";
Pnew->pr = NULL;
if (PO == NULL) PO = Pnew; // PO
//
else Pold->pr = Pnew;
Fold = Pnew;

(PO = NULL), (Pnew).


(Fold).
.
NULL. , .
, , . :
Pnew = ;
while(Pnew

NULL)

ShowMessage(Pnew->Fam +
Pnew = Pnew->pr;

" + Pnew->Nam + " ' + Pnew->Par)


//

, ..
. .

182

, . C++Builder TList TStringList,


. ,
, . 5.4.4.

2.12.3 C++
, , ,
C++. C++ (. . 2.14).
, - -. TPers.
- Show, , :
struct TPers {
AnsiString Fara, Nam, Par;
unsigned
Year;
bool
Sex;
AnsiString Dep;
TPers * pr;
void Show()
{
ShowMessage (" \""+Dep+"\" "+Fam+" "+Nam+" "+
Par+", "+IntToStr (Year) +" r.p., "+
(Sex ? "" : "") ) ;

Show : " "" , 1960 . ., ".


- . :
Pers . Show () ;
Pnew->Show() ;

Show . 2.12.2 :
Pnew = ;
while (Pnew != NULL)

Pnew->Show () ;
Pnew = Pnew->pr;

C++ - - , .
public () private ().
- . ,
.
- -,
, (), - .

C++

183


. , , . .
public .
- , private,
, . , private
public, . ,

struct MyStr { .
int x, ;
int Get () ;
private:
int a, b;
void F(> ;
};

Get
, b F
Get.
, C++ . . 2.14, .

2.12.4
++ ,
unsigned int ( . . 2.14 2.13. . .
TPers, , , , . 2047 ,
11 . , ,
12
. 1 . ,
2 ,
5 : 4 .
3 . , ,
, .

":" , (..
, ). 0 , int . :
struct TPers
AnsiStrinq
AnsiString
TPers *
unsigned
bool

{
Fam,Nam, Par ;
Dep;
pr;
Y e a r : 12;
Sex : 1;

184

.
. ,
. , . , .. . 3 :
struct Example {
unsigned a : 13;
unsigned
: 3;
unsigned b : 4;
};

,
.
. -. , ,
.

2.13
(union) , . ,
.
,
. , ,
, .

, .. . ,
, , ,
. , ,
, .

. , ,
. .
union
, (. . 2.12.1 2.14). :
union Tunion {
int

i;

double d;
char * s;
};

Tunion,
i, d, s.

C++

185

, . ,
:
Tunion N;

,
. , :
N . i = 5;
N.d = 5.1;

char *S = "";
N . s = S;

, , .
, , ,
d, .
s, ,
, s.
,
. ,
, .

2.14
- , , C++. , , . ,
. , ,
, .

2.14.1
, . ,
C++ C++Builder ,
C++Builder C++. , (.-. 2.12) (. .
2.13) C++ . , , .
, . .. .
:
class < > : < >
{
public:
//
<, , , >
published
//
<, >
protected:
//
<, , , >
private:
//
<, , , >
) < >;

186

2
:
class MyClass : public Classl, Class2
{
public:
MyClass(int = 0) ;
void SetA(int);
int GetA(void);
private:
int FA;
double , C;
protected:
int F(int);
};

. , +-Builder, "".
( -),
( -), , , - . -,
.
Classl
CIass2. -
C++Builder , , .
, - . :
class MyClassl

,
. public () ,
. .
published () ,
,
, .
private () ,
. protected () , . , . , ,
, , .

MyClass, SetA GetA. FA, , F . , . MyClass , , ,
. . .

C++

187

- ( public).
, : public ( )
-, private . . 2.14.5.
( ) private. ,
. , , . , -, .
- () , :
<> < >;

. , . 2.14.4.
- (. . 1 . 1.7.1).
, , .
C-f+Builder,
. ,
MyClass MC, MC10[10], *;

MyClass, 10
.
, , , .
,
MyClass MC(3) ;

, FA 3.
, , .
, , , . :
class MyClass : public Classl, Class2
{
} , 10[10], *Pmc;

(. . 1, . 1.11),
new. :
MyClass *PMC = new MyClass;

MyClass *1 = new M y C l a s s ( 3 ) ;

-
1.

188

, C++Builder. ,
new. , :
class MyClass2 : public TObject


MyClass2 *2 = new MyClass2;

2.14.2 -, ,

, , . , ,
, . , . ,
, - ,
.
private . protected ,
.
. :
class MyClass
{
public :
void SetA(int);
int GetA (void) ;
private :

//
//

int FA;

double , ;

};

:
void MyClass : :SetA (int Value)
{
if ( . . . )
//
FA = Value;
}
int MyClass :: GetA (void)

{ r e t u r n FA;}

,
- . , -
"::".
, . . :
class MyClass
{
public:

C++

189

MyClass(int = 0);
void SetA(int Value) {FA= Value;};
int GetA(void) {return FA;};
private:
int FA;
double , C;
};

//
//

, , inline (. .
1.7.6, ).
: , , .
,
inline:
inline void SetA(int);

//

. inline
.
, . .
- . , ,
- - .
- - -, , .
(- , ) - -. , . , friend. ,
friend void IncFA(MyClass *) ;

IncFA, , . , IncFA - :
void IncFA(MyClass *P) (P->FA++;)

, . ,
friend Classl;

- Classl .
const. :
const Classl M C I ( 3 ) ;

,
, , , .
, const.
, .

190

, .
, .
,
const. ,
int GetA(void)

const;

:
int My Class:-.Get A (void)

const {return FA;}

.
, ,
, - , , const.

2.14.3 -, ,

-.
- .

. , .
. , , ,
.
.
,
. static. :
static int D;

, (protected). . :
M y C l a s s : : D = 10;

- .
, . , : . -,
.
( , )
.
- , , - ( )
int M y C l a s s : : D = 0;

C++

191

-
.
, . , .
,
-:
class MyClass
{
public:
static int D;
static int G e t D l ( v o i d ) ;
private:
static int Dl;

int

MyClass::GetDl(void)

{return D l ; }

int MyClass::D = 0;
int M y C l a s s : : D 1 = 1;

: D D1. D1,
, GetDl.
(public) ( static). , .
GetDl.
static. , . ,
.
. :
i = MyClass::D;
j = MyClass::GetDl() ;

.
:
static const int MaxA = 10;
const int MinA;


, . , . . 2.14.4.

2.14.4
. , . ,
( , ) , .. .
. , , ,

192

. -
.
-, .
, .
:
class MyClass
{

public:

MyClass(void); //
private:
int A;

MyClass::MyClass(void) {A = 0;}

MyClass ,
0.
, .
. . , SetA, ,
. :
MyClass::MyClass(void) { S e t A ( O ) ; }

MyClass :
MyClass MC;
:
MyClass *PMC = new MyClass;

, .
,
.
- .
, . ,
MyClass(int);

M y C l a s s : : M y C l a s s ( i n t a) ( S e t A ( a ) ; }

FA , .
MyClass (1);

MyClass *PMC = new MyClass ( 1 ) ;


, FA 1.

C++

193

,
.
(.
. 1.7.4). :
MyClass (int = 0 ) ;
:
M y C l a s s : : M y C l a s s ( i n t a)

( SetA(a); }

. ,
. ,
( 0). . .
,
. :
const int MaxA;

, , FA.
,(. . 2.14.3),
:
static const int MaxA = 10;

. , . . , ,
. ,
MyClass
const int MaxA;
const int MinA;

,

MyClass(int = 0);
:
MyClass::MyClass(int a)

: (), MinA(l)

(SetA(a);};


10, MinA 1.

. :
MyClass(int A =

0,

int MaxA = 10,

int MinA =

1);

M y C l a s s ( i n t = 0,

int = 10,

int = 1);

( , ,
).
:
MyClass: -.MyClass (int a,

int i,

int j)

: MaxA(i), MinA(j)

{ SetA(a);

194

, , :
MyClass
MyClass
MyClass
MyClass

;
MC(20);
MC(20,15);
MC(20,15,2);

//
//
//
//

:
:
:
:

=
=
=
=

0,
20,
20,
20,

=
=
=
=

10,
10,
15,
15,

MinA =
MinA'=
MinA =
MinA =

1
1
1
2

-.
, , WinMain main.
#pragma startup (. . 1.4.4) , WinMain main,
.
. -,

.
, "-", ,
. :
class MyClass
{
public:
-MyClass ( ) ; //

, - -
, - .
.
.
, .

2.14.5
. . , - X,
X ();

X , . , ,
X = ;

X = ();

,
- . .
, .
, C++Builder,
, . . .
. , , - , , , -

C++

195

, .
. ,
, ..
. , .
, . :
class X
public:
int ;
X(int = 0);
};

,
:
X::(int A)
{
= ;
ShowMessage(" , = " + I n t T o S t r ( a ) ) ;
)

, ,
.
- , , :
X yl;
X 2 = (2) ;
X = 3.5;
X xl(yl);
X 2 = 2;
X = X () ;
ShowMessage (IntToStr (xl .a) + ' ' -tIntToStr(x2.a) + ' ' + IntToStr(.));

, ,
, 0, 2 3. yl, 2 . yl
- 0. 2 2 .
. , . 3.5
(, ) .
xl, 2 .
, yl, 2, xl, 2, .
. . . ,
explicit ():
explicit X ( i n t = 0 ) ;

. ,
, . ,
X. , .
, ,
, , -
.

196

,
.
, .
:
class X
{
public:
int a, b;
X(int = 0);
X(XS) ;
};

:
X: : ( & )
{
= . ;
ShowMessage(" , = " + I n t T o S t r ( a ) ) ;
}

, , .
, ,
.
xl, 2, .

2.14.6 , ,

, - , - -, , .
( ). .
public,
protected private (. . 2.14.1). .
public , .
.

.
. , .

.

197

C++


- public

protected

private

public

public
-,

, -

protected
-

private
-

protected

protected
-

protected
-

private
-

private



-
- .



-
- .



-
- .

- - (
),
. , . - ,
.
Shape:
class Shape
{
public:
void Draw(void);
};

Circl:
class Circl : public Shape

198

2
public:
void D r a w ( v o i d ) ;
};

Draw. ,
, .
Draw :
void S h a p e : : D r a w ( v o i d )
{
ShowMessage(" ");
}
void C i r c l : : D r a w ( v o i d )
{
ShowMessage("" ) ;
}

:
Shape *PQ1 = new Shape;
PQl->Draw();
Circl *PQ2 = new Circl;
PQ2->Draw();
PQ2->Shape::Draw();
((Shape * ) P Q 2 ) - > D r a w ( ) ;

// Draw Shape
// Draw Circl
// Draw Shape
// Draw Shape

, Draw
. , , . Circl, . ( ), ,
.
- Circl Draw, .
, .
. ,
Shape. Circl
Rectang ( - Rectangle,
) Square ().
Draw,
( , ).
, Shape, . , ,
. , , :
Shape *ShapeArray[3] ;

OnCreate :
ShapeArray[0] = new C i r c l ;
ShapeArray[1] = new Rectang;
ShapeArray[2] = new Square;

:
f o r ( i n t i = 0; i < 3; i++)
ShapeArray[i]->Draw();

C++

199

, , .
.
Shape,
.
. . , , , . , Shape
Draw ,
.
. Shape
:
virtual void Draw(void);

! ,
.
virtual. , - virtual, ,
. C++ .
. , .
, . 2.2 dynamic_cast. ,
. - . - .
, . () Circl, Rectang Square
Draw , , . Draw
Shape :
if (dynamic_cast<Circl *>(this) != 0)
ShowMessage("");
else if (dynamic_cast<Rectang *>(this) != 0)
ShowMessage("");
else if (dynamic_cast<Square *>(this) != 0)
ShowMessage("") ;
else ShowMessage(" ");

dynamic_cast
this -. this , . , dynamic_cast . ( ). , dynamic_cast 0.
.
, , .
,
. . -

200

. . ,
-.
( ). , .
, , :
virtual void Draw(void)=0;

Draw Shape, , . .
, ,
. . -.

2.14.7 ,
C++Builder
2.14.7.1
, C-H-Builder, . new.
, .
(property), ()
. ,
, , private. ,
'F'.
:
property <> <> = {=< >
write=<HMH >
<
>;

read write ,
.
read , . , , .
Get,
.
write , . , . Set, .
write ,
.
,
.dfm.
default >

C++

201

. .
,
, .
. MyClass, TObject .
:
class MyClassl : public TObject
I

private:
int FA;
protected:
void
f a s t c a l l S e t A ( i n t ) ; //
published:
property int A = (read = FA, write = SetA, default = true);
);

FA, SetA,
, , .
read . ,
. write SetA, . -
.
:
void
fastcall MyClassl::SetA(int Value)
{
if ( . . . ) FA = Value;
)

published.
, ,

. public, - ,
,
. write ,
, .. .

property :
property <> <> < > =
{read=<MMfl >
write=<MMH >
<
>;

, .
N :
//
class Matrix
{
float data;
int N;
//
int M;
//

202

2
public:
Matrix(int,int);
-Matrix( ) { delete[ ] data; }
property float Items [int i] [int j] =
{ read=Get!tems, write=Set!tems };
private:
float
fastcall Getltems(int i, int j);
void
fastcall Setltems (int i, int j, float value);
};
Matrix::Matrix(int n, int m)
//
{
data = new float [n*m];
//
for(int i = 0; i < n*m; i++) //
data[i] = 0.;
N = n;
M = m;
}
void
fastcall Matrix::Setltems(int i, int j, float value)
{
// value (i,j)
if ( (i<l) I I (i>N) I I (j<l) I I (j>M) )
ShowMessage(" (" + intToStr(i) +
", " + IntToStr (j) + ") ") ;
else data[(i-l) * M + j - 1] = value;
}
float
fastcall Matrix: .-Get I terns (int i, int j)
{
// (i,j)
if ( ( i < l ) I I (i>N) | | (j<l) | | ( j > M ) )
ShowMessage(" (" + I n t T o S t r ( i ) +
"," + IntToStr ( j ) + " ) " ) ;
else return d a t a f ( i - l ) * M + j - 1]-;
}

Matrix.
Items, .

property: float Items [int i] [int j].
i j .
: [int] [int].
.
Getltems , .
1, , , , .
Setltems value
, .
, , , :
Matrix x ( 4 , 5 ) ;

4 x 5 . Items. :
. I t e m s [ 2 ] [ 3 ] = 1.5;
f l o a t = . I t e m s [ 2 ] [3];

1,5 3- 2- ,
.

C++

203

2.14.7.2
- - , .
C++Builder ,
TObject ( this), TNotifyEvent. C++Builder OnClick ,
- - TObject *Sender.
, . :
private :
TNotifyEvent FMyEvent;
_ published:
_ property TNotifyEvent MyEvent = {read= FMyEvent,
write= FMyEvent};

,
. , , ,
true, . ,
, ,
, , . :
if (FMyEvent) OnMyEvent (this) ;

OnMyEvent, , . , "On".
, , .
- , . - , Windows,
.
- this,
TNotifyEvent
. _ closure. :
typedef vc^id _ fastcall ( _ closure *TMyEvent)
(System: :TObject *Sender, bools MyParam) ;
class : public TObject
{
private
TMyEvent FMyEvent;
published
_ property TMyEvent 'FMyEvent = {read= FMyEvent,
write= FMyEvent);

- .
, , .., , .

204

2.14.8
C++ ,
(generic) . ,
,
.
,
. ,
, , , , .
(. . 1.7.8).

template <class > class


, . ,
- , "". :
template <class T> class Matrix

Matrix . .
( )
.
. , float. class,
, , . C++ typename.
:
template <typename T> class Matrix
f

He typename ( C++Builder 6 ),
class.
, ,
. 2.14.6.1.
//
template <class T> class Matrix
{
*data;
int N;
//
int M;
//
public:
Matrix(int,int) ;
-Matrix( ) { delete[ ] data; }
property Items [int i] [int j] =
{ read=Get!tems, write=Set!tems } ;
private:

fastcall Getltems(int i, int j);


void
fastcall Setltems(int i, int j, value);

C++

205

//
template <class T> Matrix<1> : :Matrix (int n, int m)
(
data = new T [ n * m ] ;
f o r (int i = 0; i < n*m;
data[i] = 0;
N = n;
M = m;

template <class T> void _ fastcall


Matrix<T>: :SetItems (int i, int j , value)

// value (i,j)

if ( (i<l) I I (i>N) ] | (j<l) | | (j>M) )


ShowMessage (" (" + intToStr(i) +
", " + IntToStr (j) + ") ") ;
else data[(i -I) * M + j - 1] = value;

template <class T> _ f a s t c a l l


Matrix<T>: : Getltems (int i,
{
// (i,j)
if ((i<l) | I (i>N) I | ( j < l ) I | (j>M) )

int j)

ShowMessage (" (" + IntToStr (i) +


", " + IntToStr ( j ) + ") ") ;
return 0 ;
}
else return d a t a [ ( i - 1) * M + j 1] ;
}

. 2.14.6.1, ,
float,
. 2.14.6.1, . . : , , .. .
2.14.6.1 -
.
, , , :
Matrix<float> x ( 4 , 5 ) ;

4 x 5 .
. 2.14.6.1 '
, ,
. (
float) , .

, . 2.14.6.1, Items. :
. Items [2] [3] = 1.5;
float = . Items [2] [3] ;

1,5 3- 2- ,
.

206


typename , . ,
. ,
:();

: - ,
:, -
( C++).
.
typename, . :
typename : ( ) ;

, .

3
, C++,
C++Builderf API Windows
650 , C++, C++Builder,
API Windows. , .

, . [2].

. 4. . , Ceil. ,
. 4. .
. , , . 4, .

3.1
3.1.1
,
, , Key OnKeyDown OnKeyUp.
, .

Fl

112

0x70

VK_F1

F2

113

0x71

VK_F2

F3

114

0x72

VK_F3

F4

115

0x73

VK_F4

F5

116

0x74

VK_F5

F6

117

0x75

VK_F6

F7

118

0x76

VK_F7

F8

119

0x77

VK_F8

F9

120

0x78

VK_F9

F10

121

0x79

VK_F10

32

0x20

VK_SPACE

Backspace

0x8

VK_BACK

Tab

0x9

VKJTAB

208

Enter

13

OxOD

Shift

16

0x10

VK_SHIFT

Ctrl

17

Oxll

VK_CONTROL

Alt

18

0x12

VK_MENU

CapsLock

20

0x14

VK_CAPITAL

Esc

27

OxlB

VK_ESCAPE

Insert

45

Ox2D

VK_INSERT

PageUp

33

0x21

VK_PRIOR

PageDown

34

0x22

VK NEXT

End

35

0x23

VK_END

Home

36

0x24

VK_HOME

<-

37

0x25

VKJLEFT

38

0x26

VK_UP

>

39

0x27

VKJRIGHT

40

0x28

VK_DOWN

Delete

46

Ox2E

VK_DELETE

_ VK_RETURN

PrintScreen

44

Ox2C

VK_SNAPSHOT

ScrollLock

145

0x91

VK_SCROLL

Pause

19

0x13

VK_PAUSE

NumLock

144

0x90

VKJ4UMLOCK

o,)

48

0x30

'0'

1, !
2, @

49

0x31

'1'

50

0x32

'2'

3, #

51

0x33

'3'

4,$

52

0x34

'4'

5, %

53

0x35

'5'

6, "

54

0x36

'6'

7, &

55

0x37

'

8,*

56

0x38

'&'

9, (

57

0x39

'9'

192

OxCO

189

OxBD

=+

187

OxBB

[{

219

OxDB

]}

221

OxDD

, C++, C++Builder, API Windows

209

;;

186

222

OxDE

\l
<

220

OxDC

188

>

190

/?

191

OxBF

65

0x41

''

66

0x42

''

67

0x43

''

d, D

68

0x44

'D'

69

0x45

f, F

70

0x46

'
-

9, G

71

0x47

'G'

h, H

72

0x48

'

73

0x49

'

74

'

k,

75

''

1, L

76

'L'

m, M

77

Ox4D

n, N

78

'N'

,0

79

Ox4F

80

0x50

''
-

q, Q

81

0x51

Q'

, R

_ 82

0x52

'R'

s, S

83

0x53

'S

t,T

84

0x54

''

, U

85

0x55

v, V

86

0x56

w, W

87

0x57

'W"

, X

88

0x58

'X'

, Y

89

0x59

z, Z

90

'Z'

NumLock

96

0x60

VK_NUMPADO

97

0x61

VK_NUMPAD1

210

98

0x62

VK_NUMPAD2

99

0x63

VK_NUMPAD3

100

0x64

VK_NUMPAD4

101

0x65

VK_NUMPAD5

102

0x66

VK_NUMPAD6

103

0x67

VK_NUMPAD7

104

0x68

VK_NUMPAD8

9
*

105

0x69

VK_NUMPAD9

106

VK_MULTIPLY

107

VK_ADD

109

Ox6D

VK_SUBTRACT

110

VK_DECIMAL

111

Ox6F

VK_DIVIDE

, ,
OnKeyDown , . Key,
. , , . ,
"Y" ""- , , "" "",
. .
, Key , . , Enter :
i f ( K e y == 13) . . . ;

Key , . ,
:
if(Key == OxOD) . . . ;

, , , ,
. ,
:
i f ( K e y == VK^RETURN) . . . ;

, ,
. ,
, Key. , ,
, "Y", :
i f ( K e y == ' Y ' ) . . . ;

, C++, C++Builder, API Windows

211


. "" , "" "", .

3.1.2

(. . 2.4) Windows.

33
38
43
48
53
58
63
68
73
78
83
88
93
98
103
108
113
118
123
133
149
167
174
182
192
197
202
207
212

!
&
+
0
5
:
?
D
I
N
S
X

q
V

{
...

11

34
39
44
49
54
59
64
69
74
79
84
89
94
99
104
109
114
119
124
145
150
168
176
183
193
198
203
208
213

6
*

h
m

w
<

35
40
45
50
55
60
65
70
75
80
85
90
95
100
105
110
115
120
125
146
151
169
177
184
194
199
204
209
214

#
(
2
7
<

d
i
n
s
X

3
M

36
41
46
51
56
61
66
71
76
81
86
91
96
101
106
111
116
121
126
147
153
171
178
185
195
200
205
210
215

)
.

3
8
=

G
L
Q
V
[
'

37
42
47
52
57
62
67
72
77
82
87
92
97
102
107
112
117
122
132
148
166
172
179
187
196
201
206
211
216

%
*
/
4
9
>

R
W

f
k

J)

212

217
222
227
232
237
242
247
252

218
223
228
233
238
243
248
253

219
224
229
234
239
244
249
254

220
225
230
235
240
245
250
255

221
226
231
236
241
246
251
-

3.1.3 ,

3.1.3.1
, (printf.
cprintf. sprintf .)> , .

.
% :
%[flags][width][.precision][F|N|h|l|L]type

.
type , . :
[flags]
[width]
[.precision]
[F|N|h|l|L]

, , , , (, )


, :
N
(near)
F
(far)
h
short int
I
long
L
long double

type.

, C++, C++Builder, API Windows

signed integer
signed integer
unsigned integer
unsigned integer
unsigned int ( ,
b, c, d, e, f)
, , , , , D, , F
: [-Jdddd.dddd

u
X

X
f
e

(i

213

() : [-Jd.dddd
e[+/-]ddd
, ,
f ;

, g,



,
%

int

, ,
;

XXXX:YYYY, YYYY ( )

flags .

, . , ,
.
(+) ( ).
,
(+). (-)
. +,
.

214

, X, X 0, , ,
, , f, g, G . g, G
.

width . , (*). ,
.
width .
, .
:

On
*

.
, ( , ) .
.
, .
.

precision
. (.),
width. , width, ,
(*). ,
.
precision :

1
6


d, i, , u, x, X
, , f
g, G
s

precision:
.0
.11

d, i, , u, x .
, , f .
.
, , ( ).
.

, C++, C++Builder, API Windows

215

precision .

d, i, , u, x, X , ,
,
. , .
, , f
,
. .
, .
g. G
.

, .

%f

%g

%#G

110000.000000

1.100000+05

110000

-110000000.000000

-1.100000+08

-1.1+08

110000.
-1.10000+08

0.000110

1.100000-04

0.00011

0.000000
12.000000

1.100000-07

1.1-07

0.000110000
1.10000-07

1.200000+01

12

12.0000

0.000000

.+00

0.00000

12
-12

%6i

%-6i

12
-12

%+6i

+ 12
-12

%06i

000012
-00012

%f

%.5f

123456789.000000
123456789.00000

0.123457
0.12346

% .3f

123456789.0000
123456789.000

%e

1.234568e+08

0.1235
0.123
1.234568e-01

%.5e

1.23457e+08

1.23457e-01

% At

216

%
%.3
%g

%.5g
%.4g
%.3g
%.2g

1.2346e+08

1.2346e-01

1.235e+08
1.23457e+08
1.2346e+08
1.235e+08
1.23e+08
1.2e+08

1.235e-01
0.123457
0.12346
0.1235
0.123
0.12

. 4
.
3.1.3.2
,
(scanf. fscanf. sscanf .). :
( " ", "\t", "\"
( %)

,
,
().
,
, . , .
% :
% [*] [width] [ F | N ] [ h | l | L ] type

.
type , , .
:

[*]
[width]

[F|N]

[h|l|L]

. ,
. .
. , ,
.
, :
N
(near)
F
(far)
, :
h
short int
1
long int, type , double, type
L
long double

, C++, C++Builder, API Windows

217

type.

int (int *arg)

long (long *arg)

float (float *arg)

float (float *arg)

g,G

float (float *arg)

int (int *arg)


long (long *arg)


, int (int *arg)

, long (long *arg)

unsigned int (unsig
ned int *arg)
unsigned long (un
signed long *arg)

i
I

int (int *arg)


int (int *arg)


(char arg[])
char (char *arg) ,
(, %5),
W (char arg[W])

hit (int *arg)

:
YYYY:ZZZZ ZZZZ

,
,



(far* near*)

. 4
.
3.1.3.3 Format
Format.
FormatBuf, FmtStr, StrFmt, StrLFmt .

218

. , .
% :
"%" [index " : " ]

["-"]

[width]

[ " . " prec] type

type , , . :
[index ":"]
index. 0. , % 0: .
["-"]
. ["--"] .
[width]

. , ( , [""]) .
["." prec] , ( ). (.), width.
index, width prec
(*). ,
.
type.

.
["." prec],

. , .
"-d.ddd...E+ddd".

.
["." ],
,
( 15 ). ""
.

"ddd.ddd...". ["."
],
( 2 ).

, C++, C++Builder, API Windows

219


, , . ["."
], ( 15).
, ,
.
,
0.00001.
.

, , : "-d,ddd,ddd.ddd...".

, . CurrencyString, Currency Format, NegCurrPormat, ThousandSeparator, DecimalSeparator, CurrencyDecimals, Currency Format International Windows. ["."
], CurrencyDecimals.


"XXXX:YYYY", YYYY
, .

,
PChar

.
["." ], .
, .

. ["."
],
. ,
.

, .
DecimalSeparator ThousandSeparator.

%f

%g

110000.

110000,00

1+005

110000

-1.1+08

-110000000,00

-1+008

-110000000

220

%f

%g

0.00011

0,00

1 , 10000000000000-004

0,00011

1.1-07

0,00

1-007

1-7

12.

12,00

1,20000000000000+001

12

0,

0,00

0,+000

:
/ 1-4

12.

0,00

%.2f

0,00

12,00

0,000

%.3f

0,000

12,000

0,0000

% .4f

0,0001

12,0000

.+000

%.2

1-007

1,2+001

0,+000

% .

1-007

1,20+001

0,+000

% .4

1-007

1.200+001

.+000

%.2g

1-7

12

%.3g

1-7

12

% -4g

1-7

12

3.1.3.4 TFloatFormat TFIoatValue



TFloatFormat TFIoatValue , FloatToText, FloatToStrF. FloatToDecimal,
TextToFloat.

#include <SysUtils.hpp>
enum TFloatFormat { ffGeneral, ffExponent, ffFixed, ffNumber,
ffCurrency };
enum TFIoatValue { fvExtended, fvCurrency };

TFIoatValue . fvExtended , fvCurrency


Currency.
TFloatFormat FloatToText, FloatToStrF. FloatToDecimal, TextToFloat. :
ffGeneral

. ,
. ,
.
, Precision 0.00001. ,
Digits 0 4.

, C++, C++Builder, API Windows

221

ffExponent .
"-d.ddd...E+dddd". , , Precision. ""
"+" " " . Digits 0 4.
ffFixed

.
"-ddd.ddd...". . Digits,
18. Precision, .

ffNumber

.
'-d,ddd,ddd.ddd...". ffFixed .

ffCurrency

. ,
. CurrencyString, CurrencyFormat, NegCurrFormat, ThousandSeparator, DecimalSeparator,
Currency Format International
Windows.
Digits, 0 18.

, ,
DecimalSeparator Thousands eparat or.
3.1.3.5 FormatFloat
, , FormatFloat, FloatToTextFmt, FormatFloat AnsiString
.
:

. ,
"", .
"".
. ,
"#", .

.
. "." . "." . , , DecimalSeparator, Number Format International
Windows.

222

.
",",
. "," , . ,
, ThousandSeparator, Number Format
International Windows.

+, +,

. "+", "-", "+" "-", .


"" ( ),
.
"+" "+", ,
"+" "-". "-" "-", .

''/""

, , , .
,
, .

"" "" ,
.
,
"" "#" .
,
.
,
"" "#",
.
, . ,
. ,
, . , , , .
(..
), .
, 15 . ffGeneral TFloatFormat (. . 3.1.3.4). ,
18
.

, C++, C++Builder, API Windows

223

1234

-1234

0.5

1234

-1234

0.00
#.##

1234,00

-1234,00

0,50

0,00

1234

-1234

,5

#,##0.00
#,##0.00;(#,##0.00)
#,##0.00;;

1 234,00
1 234,00
1 234,00

-1 234,00
(1 234,00)

0,50

0,00

0,50

0,00

-1 234,00

0,50

.+00
#.###-0

1.234+03
1,234

-1.234+03 5,-01
-1,234
5-1

.+00

3.1.4 ,
,
#include <errno.h>

3.1.4.1 _doserrno, errno _sys_nerr ,



_doserrno int
. _<18
, ,
, UNIX.
, , _sys_errlist, . _sys_nerr,
( stdio.h)
stder.
_sys_errlist[errno], _sys_errlist[_sys_nerr].
0.
, .. . ,
0.
3.1.4.2
, ,
_sys_errlist.

_sys_errlist

E2BIG
EACCES

20

EAGAIN
EBADF

42

Arg list too long


Permission denied
Resource temporarily unavailable

Bad file number

EBUSY

44

Resource busy

224

ECHILD
ECONTR
ECURDIR
EDEADLOCK

_sys_errlist

24

No child process
Memory blocks destroyed
Attempt to remove CurDir

EDOM
EEXIST
EFAULT

33

EFBIG
EINTR
EINVACC
EINVAL

27

EINVDAT
EINVDRV
EINVENV
EINVFMT
EINVFNC
EINVMEM

13

40

EISDIR
EMFILE
EMLINK
ENFILE

46

ENMFILE
ENODEV
ENOENT
ENOEXEC
ENOFILE
ENOMEM
ENOPATH
ENOSPC
ENOTBLK
ENOTDIR
ENOTSAM
ENOTTY
ENXIO
EPERM

18

16
36
35
14
39
12
19
15
10
11
1

31
23
15
2

21
2
8
3

28
43
45
17
25
41
37

Locking violation
Math argument
File already exists
Unknown error
UNIX MSDOS
Interrupted function call
Invalid access code
Invalid argument
Invalid data
Invalid drive specified
Invalid environment
Invalid format
Invalid function number
nvalid memory block address
Input/output error
UNIX MSDOS
Too many open files
UNIX MSDOS
Too many open files
No more files
No such device
No such file or directory
Exec format error
File not found
Not enough core
Path not found
No space left on device
UNIX MSDOS
UNIX MSDOS
Not same device
UNIX MSDOS
No such device or address
Operation not permitted

. C++, C++Builder, API Windows

EPIPE

_sys_errlist

32

Broken pipe

ERANGE

34

EROFS
ESPIPE

30

Result too large


Read-only file system

ESRCH

38

Illegal seek
UNIX MSDOS

ETXTBSY
EUCLEAN

26

UNIX MSDOS

47

UNIX MSDOS

22

Cross-device link

Error 0

EXDEV
EZERO

29

225

. ,
strcpy(_sys_errlist[ENOENT]," ");
"No such file or directory".

-- -, , C++Builder I/O
checking Pascal . ++ilder EInOutError.

2
3
4

100


(EOF)

101

106

3.1.4.3 EDOM, ERANGE


EDOM ERANGE
. , , errno, :
i f ( e r r n o == EDOM)

3.1.4.4 jnatherr jnatherrl

#include <math.h>
int _matherr(struct _exception *e);
int _matherrl(struct _exceptionl *e);

_matherr _matherrl ( long double) , -

226

( ..). , , , ,
0. signal.
_matherr _matherrl
, .
, .
. _matherr _matherrl , 0.
.
:
*
struct _exception {
int
type;
char
*name;
double a r g l , arg2, retval;
};
struct _exceptionl {
int
type;
char
*name;
long double argl, arg2, retval;
};

type . name
, , . argl
arg2 , (
, argl). retval . .
, type, :
DOMAIN
SING
OVERFLOW
UNDERFLOW
TLOSS

; ,
log(-l)
; ,
pow(0, -2)
,
DBL_MAX ( LDBL_MAX); , ()
,
DBL_MIN ( LDBL_MIN); , (-)

; , sin(10e70)

DBL_MAX, DBL_MIN,
LDBL_MAX LDBL_MIN float.h.

,
DOMAIN sqrt ( ),
:
int _matherr (struct _exception *a)
{
if (a->type == DOMAIN)
if ( ! s t r c m p ( a - > n a m e , " s q r t " J ) {

, C++, C++Builder, API Windows

227

a->retval = sqrt (- (a->argl));


return 1;
return 0;

3.1.5 Windows
. 1.14, . 4 Windows. .
WM_ACTIVATE
, . , , .

WM_ACTIVATE
fActive = LOWORD(wParam);
fMinimized = (BOOL) HIWORD(wParam);
hwndPrevious = (HWND) IParam;

fActive , . :
WA_ACTIVE

(,
Set Active Window )

WA_CLICKACTIVE

WA_INACTIVE

fMinimized , , .
hwndPrevious , ,
, , , , .

, .

, .

,
WMJMOUSEACTIVATE.
WM_ACTIVATEAPP

. .

WM_AC TIVATEAPP
fActive = (BOOL) wParam;
dwThreadJD = (DWORD) IParam;

228

fActive true , , a false


.
dwThreadID , .

, .
WM_CANCELMODE
,
.
.

, .

.
WM_CLOSE
, .

WM_CLOSE


, .

DestroyWindow, .


DestroyWindow .
WM_GETMINMAXINFO
. .

WM_GETMINMAXINFO
Ipmmi = (LPMINMAXINFO) IParam;

Ipmmi MINMAXINFO,

. :
typedef struct tagMINMAXINFO {
POINT ptReserved;
POINT ptMaxSize;
POINT ptMaxPosition;
POINT ptMinTrackSize;
POINT ptMaxTrackSize;
} MINMAXINFO;

, C++, C++Builder, API Windows

229

:
ptReserved

ptMaxSize

Point (Point .)
(Point.y)

ptMaxPosition

Point (Point. )
(Point.y)

ptMinTrackSize

Point (Point. )
(Point.y)

ptMaxTrackSize

Point (Point. )
(Point.y)


, 0.

WM_GETMINMAXINFO 100 200 , 150 300 .


type
TForml = c l a s s ( T F o r m )
private
procedure WMGetMinMaxInf(var Info: TWMGetMinMaxInfo);
message WMJ3ETMINMAX1NFO;

end;
implementation
procedure T F o r m l . W M G e t M i n M a x I n f ( v a r I n f o : T W M G e t M i n M a x I n f o ) ;
begin
with I n f o . M i n M a x I n f o A do
begin
p t M i n T r a c k S i z e . x := 150;
p t M a x T r a c k S i z e . x := 300;
ptMinTrackSize. := 100;
ptMaxTrackSize. := 2 0 0 ;
ptMaxPosition.x:=BoundsRect.Left;
ptMaxPosition.:=BoundsRect.Top;
end;
inherited;
end;

WM_GETTEXT
, , , .

WM_GETTEXT
wParam = (WPARAM) cchTextMax;
IParam = (LPARAM) IpszText;

230

cchTextMax ,
, .
IpszText , .

.

, , .

. . .
.
, 64, EM_STREAMOUT EM_GETSELTEXT.
WM_SETFONT
, ,
.

WM_SETFONT
wParam = (WPARAM) hfont;
IParam = MAKELPARAM(fRedraw, 0);

//
//

hfont . hfont NULL, .


fRedraw true
.

.

- . . ,
, ,
.

Editl
Form2, ,
FontDialogl:
if (FontDialogl.Execute) then
SendMessage(Form2.Editl.Handle, WM_SETFONT,
FontDialogl.Font.Handle, 0);

WM_SETTEXT
, .

WM_SETTEXT
wParam = 0;
IParam = (LPARAM) (LPCTSTR)Ipsz;

, C++, C++Builder, API Windows

231

Ipsz .

true, . false
( ), LB_ERRSPACE ( ) CBJERRSPACE (
) .
CB_ERR, .

.

. . .
.
. , , CB_SELECTSTRING.

3.1.6 AnsiString
C++Builder AnsiString , vcl/dstring.h Delphi. . AnsiString .
AnsiString ==, !=, >, <, >=, <=. . , , , , . ,
, , .
AnsiString =, += () +. [ ]. 1. , S1 = "", Sl[l] '', Sl[2] '' ..
AnsiString . 2 . 2.5.2. AnsiString ( S1 , ):

AnsiCompare

hit AnsiCompare(const AnsiString& rhs) const


SI rhs . Windows , .
> 0 SI > rhs, < 0 S1
< rhs 0 Sl = rhs

AnsiCompareIC hit AnsiCompareIC(const AnsiString& rhs) const


, AnsiCompare,

AnsiLastChar

char* AnsiLastChar() const


.

232

AnsiPos

/
int AnsiPos(const AnsiString& subStr) const

subStr S1. 1. subStr S1, 0. Pos

AnsiString

AnsiS tring(apryMeHT)
. :

const char* src

c_str

CurrToStr
CurrToStrF

Delete




const AnsiString& src AnsiString src
,
const char* src,
unsigned char len len src

const wchar_t* src
src wchar_t

int src
src

double src
src
;
15
char* c_str()const
,
, AnsiString
static AnsiString CurrToStr(Currency value)
value Currency
static AnsiString CurrToStrF(Currency value,
TStringFloatFormat format, int digits)
value Currency , (. . 3.1.8). . CurrToStrF
19
void Delete(int index, int count)
, index ,
count

, C++, C++Builder, API Windows

233

FloatToStrF

static AnsiString FloatToStrF(long double value,


TStringFloatFormat format, int precision, int digits)
value ,
(. . 3.1.8).
precision digits .
7 float, 15
double 18 Extended.

Format

static AnsiString Format(const AnsiString& format,


const TVarRec *args, int size)
, format args

FormatFloat

static AnsiString FormatFloat(const AnsiString& format,


const long double& value)
value ,
format

Insert

void Insert(const AnsiString& str, int index)


str, index

IntToHex

static AnsiString IntToHex(int value, int digits)


value ,
digits

IsDelimiter

bool IsDelimiter(const AnsiString& delimiters, int index) const


true, index , delimiters.

IsEmpty

bool IsEmpty() const


true,

LastDelimiter

int LastDelimiter(const AnsiString& delimiters) const


, delimiters. ,
AnsiString s = " : \ \ f i l e n a m e . ext" ;

s .LastDelimiter ( " \ \ .:" ) ;


12 ( )

Length

int LengthQ const


LowerCase

AnsiString LowerCase() const


, .

Pos

int Pos(const AnsiString& subStr) const



subStr S1. 1. subStr S1, 0. AnsiPos

234

SetLength

StringOfChar

/
void SetLength(int newLength)
newLength .
,
static AnsiString StringOfChar(char ch, int count)
, ch count .
,
AnsiString s = AnsiString: : StringOfChar ( ' A ' , 10);

Substring

s ""
AnsiStrine SubString(int index, int count) const
,
index count

ToDouble

double ToDouble() const


. , EConvertError

Tolnt

int Tolnt() const


. , EConvertError
int ToIntDef(int defaultValue) const
. , defaultValue
AnsiString Trim() const
, ,

ToIntDef

Trim

TrimLeft

TrimRight

Unique

UpperCase

WideChar

AnsiString TrimLeft() const


, ,
AnsiString TrimRight() const
, ,
void Unique()
, ..
(refcnt) 1. ,

AnsiString UpperCaseQ const
, .
wchar_t* WideChar(wchar_t* dest, int destSize) const
dest wchar_t

, C++, C++Builder, API Windows

235

WideCharBufSize

int WideCharBufSize() const


, WideChar

3.1.7 TDateTime
, ,
systdate.h.

TDateTime Object Pascal , , , 24- , ..


. 32- 00
30 1899 . TDateTime D D .
TDateTime .
C++Builder TDateTime . ,
, Object Pascal. , TDateTime . , , TDateTime. ,
TDateTime

(Now());

Now.
: "+" "
-
, , "++" "
, double , Delphi,
.
- :
-

CurrentDate

TDateTime CurrentDate()

CurrentDateTime TDateTime CurrentDateTime()



CurrentTime

TDateTime CurrentTime()

DateString

AnsiStrinsf DateStringO const


TDateTime ,
ShortDateFormat

DateTimeString

AnsiString DateTimeStringO const


TDateTime .
ShortDateFormat.
LongTimeFormat

236

- /
DayOfWeek

int DayOfWeek() const


TDateTime (1 , 7 )

DecodeDate

void DecodeDate(unsigned short* year, unsigned short* month,


unsigned short* day) const
year, month day
TDateTime

DecodeTime

void DecodeTime(unsigned short* hour, unsigned short* min,


unsigned short* sec, unsigned short* msec) const
hour, min, sec msec TDateTime

FileDate

int FileDateO const


TDateTime,
DOS

FileDateToDateTime

TDateTime FileDateToDateTime(int fileDate)


TDateTime fileDate, DOS

FormatString

AnsiString FormatStringCconst AnsiString& format)


TDateTime,
format

TimeString

AnsiString TimeStringO const


, , , LongTimeFormat

Labell->Caption
Label2->Caption
Label3->Caption
Label4->Caption

= ;
// 26. 05.2002 18:44:07
= .DateTimeString();
= .DateString() ;
// 26. 05.2002
= .TimeString();
//18:44:07

: , , . , .

3.1.8 TStringFloatFormat -
TStringFloatFormat .

enum

TStringFloatFormat

sffGeneral, sffExponent, sffFixed,


sffNumber, sffCurrency};

, C++, C++Builder, API Windows

237

sffGeneral

:
. .
.
0.00001.
( 0 4).

sffExponent .
"-d.ddd...E+dddd". '' .
. ( ) . ''
+ , ( )
0 4.
sffFixed

. "-ddd.ddd...". '' . . ( 0 18). , .

sffN umber

.
"-d,ddd,ddd.ddd...". sffFixed
.

sffCurrency , . Windows (
CurrencyString, CurrencyFormat, NegCurrFormat,
ThousandSeparator, DecimalSeparator). ( 0 18).

3.2
3.2.1 ,

_1_1

1/

0.318309886183790671538

M_1_SQRTPI 1 /

0.564189583547756286948

_2_1

0.636619772367581343076

2 /

M_2_SQRTPI 2 /

1.12837916709551257390

2.71828182845904523536

LN10

1(10) 10 2.30258509299404568402

LN2

1(2) 2 0.693147180559945309417

MJLOG10E

logio(e) 0.434294481903251827651

238

M_LOG2E

Iog2(e) 2

1.44269504088896340736

M_PI

3.14159265358979323846

M_PI_2

n/ 2

1.57079632679489661923

M_PI_4

14

0.785398163397448309616

M_SQRT_2

2', 2

0.707106781186547524401

M_SQRT2

1.41421356237309504880

3.2.2

stdlib.h

double cabs(struct complex z)


struct complex {
double x, y;

math.h

cabsl

long double cabsl(


struct _complexl z)
struct _complex {
long double x, y;

math.h

ceil

double ceil(double x)

: , X

math.h

Ceil

int Ceil(Extended X);

: , X

Math.hpp

ceill

long double ceill(long double x)

: , X

math.h

_crotl

unsigned char _crotl(


va- stdlib.h
unsigned char val, int count) lue count

crotr

unsigned char _crotr(


va- stdlib.h
unsigned char val, int count) lue count


int abs(int x)
abs
cabs

};

};

div

div_t div(int numer, int denom)


typedef struct {
numer / denom
int quot;
//
int rem;
//
} div_t;

math.h

exp

double exp(double x)

math.h

expl

long double expl(long double x)

math.h

fabs

double fabs(double x)

math.h

, C++, C++Builder, API Windows


239

fabsl

long double fabsl(long double x)

floor

double floor( double x)

: math.h
, X

Floor

int Floor(Extended X);

: Math.hpp
, X

floorl

long double floorl(long double x) : math.h


, X

fmod

double fmod(double x, double y) / math.h

fmodl

long double fmodl(


long double x,
long double y)

/ math.h

frexp

double frexp(double x,
int *exponent)

() exponent

Frexp

void Frexp(Extended X,
X - Math.hpp
Extended &Mantissa, Mantissa
int &Exponent)
Exponent

frexpl

long double frexpl(


long double x, () int *exponent) exponent

Base
IntPower Extended IntPower(
Extended Base, Exponent
int Exponent)
labs

long labs(long int x)

Idexp

double ldexp(double x, int exp)

Ldexp

Extended Ldexp(Extended X,
-2
intP)

Idexpl

long double ldexpl(


long double x, int exp)

Idiv

typedef struct {
long int quot;
//
long int reni;
//
} ldiv_t;
ldiv_t ldiv(long int numer,
long int denom)

LnXPl

Extended LnXPl(Extended X)

log

. 2

. 2

math.h

math.h

math.h

Math.hpp

stdlib.h
math.h
Math.hpp
math.h

: math.h,
numer / denom;
stdlib.h
quot
rem

Math.hpp

double log(double x)

math.h

loglO

double loglO(double x)

math.h

LoglO

Extended LoglO(Extended X)

Math.hpp

loglOl

long double Iogl01(long double x)

( + 1)

math.h

240

Log2

Extended Log2(Extended X)

Math.hpp

log!

long double logl(long double x)

math.h

Log-N

Extended LogN(Extended Base,


Extended X)

X Base

Math.hpp

val
lrotl(
unsigned long val, count
int count)

stdlib.h

unsigned long _lrotr(


unsigned long val, int count)

val
count

stdllb.h

max

max(a, b)

- stdlib.h

b

min

min(a, b)

stdlib.h

modf

double modf(double x,
double *ipart)


ipart

math.h

modfl

long double modfl(long double x,


long double *ipart) ipart

math.h

POly

double poly(double x, int degree,


math.h
double coeffs[])
degree coeffs

Poly

X
Extended Poly(Extended X,
const double * Coefficients, Coefficients_Size
const int Coefficients_Size) Coefficients

polyl

long double polyl(long double x,


math.h
int degree,
degree long double coeffs[]) coeffs

DOW

double pow(double x, double y)

Power

Extended Power(Extended Base, Base Math.hpp


Extended Exponent) Exponent

powl

long double powl(long double x,


long double y)

Irotl

unsigned long

Irotr

Math.hpp

math.h

math.h

rotl

unsigned short _rotl(


va- stdlib.h
unsigned short value, lue count
int count)

rotr

unsigned short _rotr(


va- stdlib.h
unsigned short value, lue count int count)

sqrt

double sqrt(double x)

math.h

sqrtl

long double sqrtl(long double x)

math.h

, C++, C++Builder, API Windows

241

,
math.h Math.hpp C++Builder
.
#include <math.h>
linclude <Math.hpp>

exp, expl, Idexp, Idexpl ERANGE.


log, loglO, loglOl, logl ERANGE, EDOM.
pow powl EDOM, < 0 , = 0 <= 0.
ERANGE.
sqrt sqrtl EDOM, < 0.
Math.hpp
math.h, Extended.

3.2.3

double acos(double x)

math.h

acosl

long double acosl(long double x)

math.h

ArcCos

Extended ArcCos(Extended X)

Math.hpp

ArcCosh

Extended ArcCosh(Extended X)

- Math.hpp

Arc Sin

Extended ArcSin(Extended X)

ArcSinh

Extended ArcSinh(Extended X)

- Math.h

ArcTan2

Extended ArcTan2(Extended Y,
Extended X)

(Y / X)

ArcTanh

Extended ArcTanh(Extended X)

- Math.hpp

asin

double asin(double x)

math.h

asinl

long double asinl(long double x)

math.h

atan

double atan(double x)

math.h

atan2

double atan2(double y, double x

math.h

atan21

long double atan21(long double y, /


long double x)

math.h

atanl

long double atanl(long double x)

math.h

cos

double cos(double x)

math.h

cosh

double cosh(double x)

math.h

Cosh

Extended Cosh(Extended X)

Math.hpp

Math.hpp

Math.hpp

242

coshl

long double coshl(long double x)

math.h

cosl

long double cosl(long double x)

math.h

Cotan

Extended Cotan(Extended X)

Math.hpp

- Math.hpp
CycleToRad Extended CycleToRad(
Extended Cycles) Cycles: 2- Cycles.
DegToRad


Extended DegToRad(
Extended Degrees)
Degrees:
Degrees -: / 180.

hypot

double hypot(double x, double y)

- math.h

Hypot

Extended Hypot(Extended X,
Extended Y)


X Y

hypotl

long double hypotl(long double x, - math.h


long double y)

Math.hpp

Math.hpp


RadToCycle Extended RadToCycle(
Extended Radians)
Radians:
Radians / (2).

Math.hpp

RadToDeg


Extended RadToDeg(
Extended Radians)
Radians:
Radians 180 / .

Math.hpp

sin

double sin(double x)

math.h

SinCos

void SinCos(Extended Theta,


Extended &Sin,
Extended &Cos)

Sin Math.hpp
Cos
Theta

Sinh

Extended Sinh(Extended X)

Math.hpp

sinh

double sinh(double x)

math.h

sinhl

long double sinhl(long double x)

math.h

sinl

long double sinl(long double x)

math.h

Tan

Extended Tan(Extended X)

Math.hpp

tan

double tan(double x)

math.h

. C++, C++Builder, API Windows

243

Tanh

Extended Tanh(Extended X)

Math.hpp

tanh

double tanh(double x)

math.h

tanhl

long double tanhl(long double x)

math.h

tanl

long double tanl(long double x)

math.h

,
math.h Math.hpp C++Builder
.
#include <math.h>
#include <Math.hpp>

.
, , DegToRad CycleToRad. ,
double Rad = D e g T o R a d ( 9 0 ) ;
Rad 90 . Rad
double Rad = C y c l e T o R a d ( 0 . 2 5 ) ;
( ). 90 :
double S = s i n ( D e g T o R a d ( 9 0 ) ) ;
:
acos acosl [0, ], asin, asinl, atan, atan'2, atan21, atanl [-/2, /2]. .
RadToDeg RadToCycle. ,
double A = a t a n ( ) ;
double Al = R a d T o D e g ( a t a n ( ) ) ;
double 2 = R a d T o C y c l e ( a t a n ( T ) ) ;
(), (1) (2).
acos, acosl, asin, asinl,
[-1, + 1], (EDOM).
cosh, coshl, sinh, sinhl,
,
(ERANGE).

3.2.4

Irand

long Irand(void)
, 0 2 31 - 1

stdlib.h

244

rand

int rand(void)
, 0 RAND_MAX

stdlib.h

RandG

Math.hpp
Extended RandG(Extended Mean, Extended StdDev)
, ; Mean ,
StdDev

random

int random(int num.)


, 0 num - 1

stdlib.h

randomize

void randomize(void)
( RandG)

stdlib.h

Randomize

void Randomize(void)
RandG

Math.hpp

srand

void srand(unsigned seed)


( RandG) seed

stdlib.h

3.2.5
,
Data, Data_Size.

MaxIntValue int MaxIntValue( const int * Data, const int Data Size) Math.hpp

MaxValue

double MaxValue(const double * Data,


const int Data_Size)

Math.hpp

Mean

Extended Mean(const double * Data,


const int Data_Size)
( )

Math.hpp

MeanAndStd- void MeanAndStdDev(const double * Data,


const int Data_Size,
Extended &Mean,
Extended &StdDev)
Mean StdDev

Dev

Math.hpp

MinlntValue

int MinIntValue(const int * Data, const int Data Size) Math.hpp


Min Value

double MinValue(const double * Data,


const int Data_Size)

Math.hpp

, C++, C++Builder, API Windows

245

Moment Skew- void MomentSkewKurtosis(const double * Data,


Math.hpp
Kurtosis
const int Data Size, Extended &M1,
Extended &M2, Extended &M3,
Extended &M4, Extended &Skew,
Extended &Kurtosis)
Ml, M2, , 4, Skew, Kurtosis
Norm

Extended Norm(const double * Data,


const int Data_Size)
:

PopnStdDev

Extended PopnStdDev(const double * Data,


Math.hpp
const int Data_Size)

PopnVariance

Extended PopnVariance(const double * Data,


const int Data Size)
(. Variance)

Math.hpp

StdDev

Extended StdDev(const double * Data,


const int Data_Size)

Math.hpp

Sum

Extended Sum(const double * Data,


const int Data_Size)

Math.hpp

Sumlnt

int Sumlnt(const int * Data, const int Data Size)


Math.hpp

SumOfSquares

Extended SumOfSquares(const double * Data,


const int Data Size)

Math.hpp

SumsAndSquares

void SumsAndSquares(const double * Data,


Math.hpp
const int Data Size, Extended &Sum,
Extended &SumOfSquares)
Sum SumOfSquares

TotalVariance

Extended TotalVariance(const double * Data,


const int Data Size)

Math.hpp

Variance

Extended Variance(const double * Data,


const int Data_Size)
(. PopnVariance)

Math.hpp

Math.hpp

246

3.2.6 FPU

clear87
clearfp
controI87

controlfp

/
unsigned int _clear87 (void)
FPU
unsigned int _clearfp (void)
FPU
unsigned int _contro!87(unsigned int newcw,
unsigned int mask)
FPU
unsigned int _controlfp(unsigned int newcw,
unsigned int mask)
FPU

void _fpreset(void)

Word Get8087CW(void)
GetSOSTCW
FPU
GetExceptionMask TFPUExceptionMask GetExceptionMask(void)

GetPrecisionMode TFPUPrecisionMode GetPrecisionMode(void)
, FPU,
TFPUPrecisionMode
TFPURoundingMode GetRoundMode(void)
GetRoundMode
,
FPU, TFPURoundingMode
SetSOSTCW
void Set8087CW(Word NewCW)
FPU
SetExceptionMask TFPUExceptionMask SetExceptionMask(
void TFPUExceptionMask Mask)

SetPrecisionMode TFPUPrecisionMode SetPrecisionMode(
const TFPUPrecisionMode Precision)
,

FPU, TFPUPrecisionMode
SetRoundMode
TFPURoundingMode SetRoundMode(
const TFPURoundingMode RoundMode)
,
FPU, TFPURoundingMode
fpreset

, C++, C++Builder, API Windows

247

status87

unsigned int _status87(void)


FPU

statusfp

unsigned int statusfp (void)


FPU

. FPU (floating-point unit) . 1.9.3


. 4.

3.3
3.3.1
3.3.1.1 char *

_atoi64

int64 _atoi64(const char *s)


s

stdlib.h

_atold

long double _atold(const char *s)


s

math.h

_i64toa

char *_i64toa( int64 value, char *strP, int radix)


value ; radix ( 2 36)

stdlib.h

_itow

wchar_t *_itow(int value, wchar_t *string, int radix)


value string radix

stdlib.h

_ltoa

char *_ltoa(long value, char *string, int radix)


value ; radix ( 2 36)

stdlib.h

_strtold

long double _strtold(const char *s, char **endptr)


s

stdlib.h

_ui64toa

char *_ui64toa(unsigned

_ultow

stdlib.h
wchar_t *_ultow(unsigned long Value,
wchar_t *string, int radix)
value string radix

_wcstold

long double _wcstold(const wchar_t *s, wchar_t **endptr)


s

stdlib.h

_wtof

double _wtof(const wchar_t *s)


s

math.h

_wtoi

int _wtoi(const wchar_t *s)


s

stdlib.h

int64 value, char *strP,


stdlib.h
int radix)
value ; radix ( 2 36)

248

_wtoi64

/
int64 _wtoi64(const wchar_t *s)

stdlib.h

s
_wtol

long _wtol(const wchar_t *s)

stdlib.h

s
_wtold

long double _wtold(const wchar_t *s)

math.h

s
atof
atoi

stdlib.h,
math.h

int atoi(const char *s)

stdlib.h

double atof(const char *s)

s
atol

long atol(const char *s)

stdlib.h

s
ecvt

char *ecvt(double value, int ndig, int *dec, int *sign)

stdlib.h

value
ndig; dec ,
sign
fcvt

char *fcvt(double value, int ndig, int *dec, int *sign)

stdlib.h

value
ndig; dec ,
sign
gcvt

char *gcvt(double value, int ndec, char *buf)

stdlib.h

value buf ndec


itoa

char *itoa(int value, char *string, int radix)

stdlib.h

value string radix


strtod

double strtod(const char *s, char **endptr)

stdlib.h

s
strtol

long strtol(const char *s, char **endptr, int radix)

stdlib.h

s
strtoul

unsigned long strtoul(const char *s, char **endptr,


int radix)

stdlib.h

s unsigned long radix


ultoa

char *ultoa(unsigned long value, char *string, int radix)

stdlib.h

value string radix


wcstod

double wcstod(const wchar_t *s, wchar_t **endptr)

stdlib.h

s
wcstol

long wcstol(const wchar_t *s, wchar_t **endptr, int radix)

stdlib.h

s
wcstoul

unsigned long wcstoul(const wchar_t *s, wchar_t **endptr, stdlib.h


int radix)
s unsigned long radix

, C++, C++Builder, API Windows

249

, . ,
, .
, 0.
atof strtod "+INF" "-INF",
, "+NAN" "-NAN",
.
strtod, strtol, _strtold, strtoul, wcstod, wcstol, wcstoul
endptr NULL. , :
double = s t r t o d ( E d i t l - > T e x t . c _ s t r ( ) , NULL) ;

, Editl, . endptr:
char *endptr;
double = s t r t o d ( E d i t l - > T e x t . c _ s t r ( ) , S e n d p t r ) ;

*endptr , .
.
,
HUGE_VAL ( double)
LHUGE_VAL ( long double).

AnsiString (. . 2.5.2).
char * c_str(), .
3.3.1.2 ,
SysUtils.hpp

CurrToStr

/
System-AnsiString CurrToStr(System::Currency Value)
Value Currency
CurrToStrF
System::AnsiString CurrToStrF(System::Currency Value,
TFloatFormat Format, int Digits)
Currency TFloatFormat (. . 3.1.2.4)
FloatToDecimal void FloatToDecimal(TFloatRec &Result, const void *Value,
TFloat Value ValueType, int Precision, int Decimals)
Value ValueType (CM. TFloatValue . 3.1.2.4)
TFloatRec
System::AnsiString FloatToStr(Extended Value)
FloatToStr
Value
System::AnsiString FloatToStrF(Extended Value,
FloatToStrF
TFloatFormat Format, int Precision, int Digits)
Value TFloatFormat
(. . 3.1.2.4)

250

FloatToText

int FloatToText(char * Buffer, const void *VaIue,


TFloatValue ValueType, TFloatFormat Format,
int Precision, int Digits)
Value ValueType Buffer TFloatFormat (. . 3.1.2.4)

FloatToTextFmt

int FloatToTextFmt(char * Buffer, const void *Value,


TFloatValue ValueType, char * Format)
Value ValueType (CM. TFloatValue . 3.1.2.4)
Buffer FormatFloat (. .
3.1.2.5)

FmtStr

void FmtStr(System::AnsiString &Result,


const System::AnsiString Format,
const System::TVarRec * Args, const int Args_Size)
Args Args_Size 1
Result Format (. . 3.1.2.3)

Format

System::AnsiString Format(const System::AnsiString Format,


const System::TVarRec* Args, const int Args_Size)
Args Args_Size - 1
Format (. . 3.1.2.3)

FormatBuf

Cardinal FormatBuf(void *Buffer, Cardinal BufLen,


const void *Format, Cardinal FmtLen,
const System::TVarRec * Args, const int Args_Size)
Args Args_Size - 1
Buffer BufLen Format (. .
3.1.2.3) FmtLen

FormatCurr

System::AnsiString FormatCurr(
const System::AnsiString Format,
System::Currency Value)
Currency
FormatFloat (. . 3.1.2.5)

FormatFloat

System::AnsiString FormatFIoat(
const System::AnsiString Format,
Extended Value)
Value FormatFloat (. . 3.1.2.5)

GetFormatSettings

void GetFormatSettings(void)
,

IntToHex

System::AnsiString IntToHex(int Value, int Digits)


Value Digits

IntToStr

System::AnsiString IntToStr(int Value)


Value

, C++, C++Builder, API Windows

251

/
char * StrFmt(char * Buffer, char * Format,
const System::TVarRec * Args, const int Args_Size)
Args Args_Size - 1
Buffer Format (. . 3.1.2.3)

StrFmt

StrLFmt

char * StrLFmt(char * Buffer, Cardinal MaxLen,


char * Format, const System::TVarRec* Args,
const int Args_Size)
Args Args_Size - 1
Buffer MaxLen Format (.
. 3.1.2.3)
System::Currency StrToCurr(const System::AnsiString S)
S Currency

StrToCurr
StrToCurrDef

System::Currency StrToCurrDef(const AnsiString S,


const System::Currency Default)
S Currency
Default

StrToFloat

Extended StrToFloat(const System::AnsiString S)


S
Extended StrToFloatDef(const AnsiString S;
const Extended Default)
S Default

StrToFloatDef

StrToInt

int StrToInt(const System::AnsiString S)


S

StrToIntDef
f

TextToFloat

TrvStrToInt

int StrToIntDef(const System:: AnsiString S, int Default)


S , Default
bool TextToFloat(char * Buffer, void *Value,
TFloatValue ValueType)
Buffer Value ValueType (. TFloatValue . 3.1.2.4)
bool
fastcall TryStrToInt(const AnsiString S, int &Value)
S Value, false

,
SysUtils.hpp, ValueType, fvExtended Extended, fvCurrency -- Currency.
TFloatFormat,
. 3.1.2.4, FormatFloat, .
3.1.2.5, , Format, . 3.1.2.3.
Args Args_Size - 1. Args_Size
Args TVarRec.
, . 3.1.2.3.

252

EConvertError. "Def", , TryStrToInt, false.


FloatToDecimal Extended Currency ,
. Extended Precision 1 18.
Currency Precision ,
19 .
Decimals . , Precision Decimals . , Decimals
9999.
TFloatRec,
:
. 1, Exponent , . NAN ( ), Exponent -32768. INF INF ( ), Exponent = 32767.
Negative true, false.
, 18 ( ExtenDigits
ded) 19 ( Currency) .
. . ,
NAN INF, Digits .

Exponent

FloatToDecimal:
struct TFloatRec Result;
Extended V a l u e = . . . ;
FloatToDecimal(Result, S V a l u e , f v E x t e n d e d , 1 8 , 9 9 9 9 ) ;

Value :
Value
123.4567890123456789
1234567890123456789
-0.001234567890123456789

Exponent
3

Negative
false

Digits

19
-2

false
true

123456789012345679
123456789012345671

123456789012345681

3.3.2

asctimc

char *asctime(const struct tm *tblock)

time.h

tm

253

, C++, C++Builder, API Windows

DateUtils.hpp
Types::TValueRelationship CompareDate(
const System: :TDateTime A,
const System: :TDateTime B)
. -1 < , 0 = , +1 >
CompareDateTime Types::TValueRelationship CompareDateTime( DateUtils.hpp
const System::TDateTime A,
const System::TDateTime B)

5. -1 < , 0 = ,
+1 >
DateUtils.hpp
Types::TValueRelationship CompareTime(
2ompareTime
const System: :TDateTime A,
const System::TDateTime B)
.
-1 < , 0 = , +1
>
time.h
char *ctime(const time_t *time)
ctime
time,
time,
SysUtils.hpp
System::TDateTime Date(void)
Date

^ompareDate

SysUtils.hpp
int DateTimeToFileDate(
System::TDateTime DateTime)
DateTime DOS
SysUtils.hpp
System::AnsiString DateTimeToStr(
DateTimeToStr
System: :TDateTime DateTime)
DateTime
SysUtils.hpp
DateTimeToString void DateTimeToString(
System::AnsiString &Result,
const System::AnsiString Format,
System::TDateTime DateTime)
DateTime Result no
Format
SysUtils.hpp
void DateTimeTo SystemTime(
DateTimeTo
System: :TDateTime DateTime,
SystemTime
_SYSTEMTIME &SystemTime)
DateTime TSystemTime, API Windows
SysUtils.hpp
TTimeStamp DateTimeToTimeStamp(
DateTimeTo
System::TDateTime DateTime)
TimeStamp
DateTime TTimeStamp
SysUtils.hpp
System::AnsiString DateToStr(
DateToStr
System: :TDateTime Date)

DateTimeTo
FileDate

Date

254

DayOf

DavOfTheMonth

DavOfTheWeek

/
DateUtils.fipp
Word DayOf (const System:.-TDateTime
AValue)
AValue
Word DayOfTheMonth(
DateUtils.hpp
const System::TDateTime AValue)
AValue
DateUtils.hpp
Word DayOfTheWeek(
const System::TDateTime AValue)
AValue ( 1
7, 1 )

DavOfWeek

Word DayOfWeek(
DateUtils.hpp
const System::TDateTime DateTime)
Date ( 1
7, 1 )

DaysBetween

int DaysBetween(
DateUtils.hpp
const System::TDateTime ANow,
const System::TDateTime AThen)

DavSpan

double DaySpan(
DateUtils.hpp
const System::TDateTime ANow,
const System::TDateTime AThen)

DecodeDate

void DecodeDate(
SysUtils.hpp
const System::TDateTime DateTime,
Word &Year, Word &Month,
Word &Day)
DateTime Year,
Month, Day

DecodeDateTime

void DecodeDateTime(
DateUtils.hpp
const System::TDateTime DateTime,
Word &Year, Word &Month,
Word &Day, Word &Hour,
Word &Min, Word &Sec,
Word &MSec)
DateTime Year,
Month, Day, Hour, Min,
Sec, MSec

DecodeTime

void DecodeTime(System::TDateTime Time,


Word &Hour, Word &Min,
Word &Sec, Word &MSec)
Time Hour, Min,
Sec, MSec

SysUtils.hpp

, C++, C++Builder, API Windows

255

EncodeDate

TDateTime EncodeDate(Word Year,


SysUtils.hpp
Word Month, Word Day)
Year, Month
Day TDateTime

EncodeDateTime

TDateTime EncodeDateTime(const Word Year, DateUtils.hpp


const Word Month, const Word Day,
const Word Hour, const Word Min,
const Word Sec, const Word MSec)
Year, Month, Day
I
TDateTime, Hour, Min, Sec MSec TDateTime

EncodeTime

TDateTime EncodeTime(Word Hour,


SysUtils.hpp
Word Min, Word Sec, Word MSec)
Hour, Min, Sec MSec TDateTime

FormatDateTime

System::AnsiString FormatDateTime(
SysUtils.hpp
const System::AnsiString Format,
System::TDateTime DateTime)
DateTime
Format

getdate

void getdate(struct date *datep)


datep

dos.h

gettime

void gettime(struct time *timep)


timep

dos.h

gmtime

struct tm *gmtime(const time_t *timer)


timer, time, tm

time.h

HourOf

Word HourOf(const System::TDateTime


AValue)
AValue

DateUtils.hpp

HourOfTheDav

Word HourOfTheDay(
DateUtils.hpp
const System::TDateTime AValue)
AValue

HoursBetween

DateUtils.hpp
int HoursBetween(
const System: :TDateTime ANow,
const System: :TDateTime AThen)

HourSpan

DateUtils.hpp
double HourSpan(
const System::TDateTime ANow,
const Systenv.-.TDateTime AThen)

256

IncMonth

SysUtils.hpp
System::TDateTime IncMonth(
const System:: TDateTime Date,
int NumberOfMonths)
Date, NumberOfMonths

IsLeapYear

bool IsLeapYear(Word Year)


true, Year

IsToday

bool IsToday(const System::TDateTime


DateUtlls.hpp
AValue)
true, AValue

local time

struct tm *localtime(const time_t *timer)


timer, time, tm

MilliSecondOf

Word MilliSecondOf(
DateUtils.hpp
const System::TDateTime AValue)
AValue

MilliSecond
OfTheSecond

Word MilliSecondOfTheSecond(
DateUtils.hpp
const System::TDateTime AValue)
AValue

MilliSecondsBetween

int MilliSecondsBetween(
DateUtils.hpp
const System::TDateTime ANow,
const System::TDateTime AThen)

MilliSecondSpan

double MilliSecondSpan(
DateUtils.hpp
const System::TDateTime ANow,
const System::TDateTime AThen)

MinuteOf

Word MinuteOf(
DateUtils.hpp
const System::TDateTime AValue)
AValue

SysUtils.hpp

time.h

MinuteOfTheHour Word MinuteOfTheHour(


DateUtils.hpp
const System::TDateTime AValue)
AValue
MinutesBetween
int MinutesBetween(
DateUtils.hpp
const System::TDateTime ANow,

const System::TDateTime AThen)


257

, C++, C++Builder, API Windows

MinuteSpan

double MinuteSpan(
Datelltils.hpp
const System::TDateTime ANow,
const System: :TDateTime AThen)

mktime

time_t mktime(struct tm *t)


tm
time_t

MonthOf

Word MonthOf(const System::TDateTime


DateUtils.hpp
AValue)
AValue

MonthOfTheYear

Word MonthOfTheYear(
DateUtils.hpp
const System: :TDateTime AValue)
AValue

MonthsBetween

int MonthsBetween(
DateUtils.hpp
const System::TDateTime ANow,
const System: :TDateTime AThen)

MonthSpan

double MonthSpan(
DateUtils.hpp
const System::TDateTime ANow,
const System: :TDateTime AThen)

MSecsToTime
Stamp

TTimeStamp MSecsToTimeStamp(
SysUtils.hpp
System: :Comp MSecs)
MSecs TTimeStamp

Now

System::TDateTime Now(void)

SecondOf

Word SecondOf (const System::TDateTime


DateUtils.hpp
AValue)
AValue

SecondOfThe
Minute

Word SecondOfTheMinute(
DateUtils.hpp
const System: :TDateTime AValue)
AValue

SecondsBetween

int SecondsBetween(
const System::TDateTime ANow,
const System::TDateTime AThen)

time.h

SysUtils.hpp

DateUtils.hpp

258

SecondSpan

double SecondSpan(
const System: :TDateTime ANow,
const System: :TDateTime AThen)

DateUtils.hpp

setdate

dos.h
void setdate(struct date *datep)
datep ( )

settime

void settime(struct time *timep)


timep

dos.h

stime

int stime(time_t *tp)


tp

time.h

StrToDate

System::TDateTime StrToDate(
SysUtils.hpp
const System::AnsiString S)
S TDateTime
System::TDateTime StrToDateDef(
SysUtils.hpp
const AnsiString S,
const System::TDateTime Default)
S TDateTime, Default

StrToDateDef

StrToDateTime

System::TDateTime StrToDateTime(
const System:: AnsiString S)
S TDateTime

SysUtils.hpp

StrToDateTime

System: .-TDateTime StrToDateTimeDef(


const AnsiString S,
const System: :TDateTime Default)
S TDateTime, Default

SysUtils.hpp

StrToTime

System::TDateTime StrToTime(
const System::AnsiString S)
S TDateTime

SysUtils.hpp

StrToTimeDef

System::TDateTime StrToTimeDef(
const AnsiString S,
const System: :TDateTime Default)
S TDateTime,
Default

SysUtils.hpp

SystemTime
ToDateTime

System::TDateTime SystemTimeToDateTime( SysUtils.hpp


const _SYSTEMTIME &SystemTime)
TSystemTime, API Windows, TDateTime

Def

, C++, C++Builder, API Windows

259

time

time_t time(time_t *timer)



timer ( timer NULL)

time.h

Time

System-TDateTime Time(void)

SysUtils.hpp

TimeStamp
ToDateTime

System::TDateTime TimeStampToDateTime( SysUtils.hpp


const TTimeStamp &TimeStamp)
TTimeStamp
TDateTime

TimeStampTo
MSecs

System::Comp TimeStampToMSecs(
SysUtils.hpp
const TTimeStamp &TimeStamp)
64-

TimeToStr

System::AnsiString TimeToStr(
SysUtils.hpp
System::TDateTime Time)

Today

TDateTime
fastcall Today(void)

DateUtils.hpp

Tomorrow

TDateTime
fastcall Tomorrow(void)

DateUtils.hpp

TrvEncodeDate

bool TryEncodeDate(Word Year, Word Month, SysUtils.hpp


Word Day, System::TDateTime &Date)
Year, Month
Day Date, false

TrvEncodeDate
Time

bool TryEncodeDateTime(const Word Year,


SysUtils.hpp
const Word Month, const Word Day,
const Word Hour, const Word Min,
const Word Sec, const Word MSec,
System-TDateTime & Value)
Year, Month,
Day TDateTime, Hour, Min,
Sec MSec TDateTime, false

TrvEncodeTime

bool TryEncodeTime(Word Hour, Word Min, SysUtils.hpp


Word Sec, Word MSec,
System::TDateTime &Time)
Hour, Min, Sec MSec Time, false

YearOf

Word YearOf (const System: :TDateTime


AValue)
AValue

DateUtils.hpp

260

YearsBetween

int YearsBetween(
DateUtils.hpp
const System: :TDateTime ANow,
const System: :TDateTime AThen)

YearSpan

double YearSpan(
DateUtils.hpp
const System: rTDateTime ANow,
const System: :TDateTime AThen)

Yesterday

TDateTime
fastcall Yesterdav(void)

DateUtils.hpp

TDateTime (. .
3.1.7), ,
, .
TTimeStamp. , .
, DOS.
, FileAge, FileGetDate, FileSetDate, Time
TSearchRec, FindFirst FindNext.
TDateTime DateTimeToFileDate.
, TSystemTime,
_SYSTEMTIME. API Windows. TDateTime DateTimeToSystemTime, SystemTimeToDateTime.
dos.h date:
struct date{
int da_year;
char da_day;
char da_raon;

//
//
// (1 )

, . .
D date :
#include <dos.h>
struct date D;
getdate(&D);

: D.da_year,
D.da_mon, D.da_day.
:
struct time {

unsigned char ti_min;


unsigned char ti_hour;

//
//

unsigned char ti hund;


unsigned char ti_sec;

//
//

261

, C++, C++Builder, API Windows

time , 0 1
1970 . , , , ..,
ctime . :
Mon Nov 21 11:31:54 1 9 8 3 \ \ 0

, .
, time,
gmtime ( ) localtime ( ) tm:
struct tm {

int
int
int
int
int
int
int
int
int

tm sec;
tm min;
tm hour;
tm mday;

tm mon;
tm
tm
tm
tm

year;
wday;
yday;
isdst

//
//
//
//
//
//
//
//
//

(0 - 23)
(1 31)
(0 - 11)
( 1900)
(0 6; 0
(0 -3651
12-

asctime. , :
time_t t = t i m e ( N U L L ) ;
struct tm *tt = l o c a l t i m e ( & t ) ;
char s [80] ;
strcpy(s, a s c t i m e ( t t ) ) ;

tm, , time gmtime, s. , , ctime .. .

3.3.3

Bounds

CurrTo
FMTBCD
FMTBCD

Point

/
Windows::TRect Bounds(int ALeft, int ATop,
int AWidth, int AHeight)
ALeft AWidth
AHeight TRect
bool CurrToFMTBCD(System::Currency Curr,
Bde::FMTBcd &BCD, int Precision, int Decimals)
Curr Bde::FMTBcd
bool FMTBCDToCurr(const Bde::FMTBcd &BCD,
System: :Currency &Curr)
BCD Currency
TPoint Point(int AX, int AY)
AY TPoint

Classes.hpp

DBCommon.hpp

DBCommon.hpp

Classes.hpp

262

Rect

/
Classes.hpp
Windows::TRect Rect(int ALeft, int ATop,
int ARight, int ABottom)
Windows::TRect Rect(constTPoint ATopLeft,
const TPoint ABottomRight)
ALeft, ATop, ARight, ABottom
ATopLeft, ABottomRight TRect

CurrToFMTBCD FMTBCDToCurr Currency Bde::FMTBcd,


BCD .

3.4
3.4.1

_tolower

int _tolower(int eh)



( )

ctype.h

_toupper

int _toupper(int ch)


ctype.h

( )
int isalnum(int )
ctype.h

isalnum
isalpha

int isalpha(int )

ctype.h

isascii

int isascii(int )
ASCII

ctype.h

iscntrl

int iscntrl(int )

ctype.h

isdigit

int isdigit(int )

int isgraph(int )

int islower(int )

int isprint(int )

ctype.h

isgraph
islower
isprint
ispunct


ctype.h
( )
ctype.h

ctype.h
( )

int ispunct(int )
( , , , )

ctype.h

, C++, C++Builder, API Windows

isspace

isupper
iswalnum
iswalpha
iswascii
iswcntrl
iswdigit
iswgraph
iswlower
iswprint
iswpunct

iswspace

iswupper
iswxdigit
isxdigit
toascii

tolower

263

/
int isspace(int c)
(, , )
int isupper(int )

int iswalnum(wint_t )

int iswalpha(wint_t )

int iswascii(wint_t )
ASCII
int iswcntrl(wint_t )

int iswdigit(wint_t )

int iswgraph(wint_t )
( )
int iswlower(wint_t )

ctype.h

int iswprint(wint_t )
( )
int iswpunct(wint_t )
( , , , )
int iswspace(wint_t )
(, , )
int iswupper(wint_t )

int iswxdigit(wint_t )

ctype.h

ctype.h

ctype.h
ctype.h
ctype.h

ctype.h
ctype.h
ctype.h
ctype.h

ctype.h

ctype.h

ctype.h
ctype.h

ctype.h
int isxdigit(int )

ctype.h
int toascii(int )
ASCII (
, 7 ) 0 127)
ctype.h
int tolower(int ch)
,

264

toupper

/
int toupper(int ch)
,

towlower

ctype.h
int towlower(wint_t ch)
,

ctype.h
int towupper(wint_t ch)
,

towupper

ctype.h

, ,
, . (. . 3.4.2.2 3.4.2.3): , . ,
Key = AnsiUpperCase(Key);
Key char .

3.4.2
3.4.2.1

/
mem.h
wmemcpv void * wmemcpy(void *dest, const void *src, size t n)
src dest; src dest (. memmove); dest
mem.h
wmemset void * wmemset(void *s, int , size t n)
n s ; s

memccpy

memchr

void *memccpy(void *dest, const void *src, int c, size t n) mem.h


src dest,
n ; dest
void *memchr(const void *s, int c, size_t n)
mem.h
n s; , NULL

memcmp

int memcmp(const void *sl, const void *s2, size_t n)


n si s2; < 0
si < s2, = 0 si = s2, > 0 si > s2

mem.h

memcpv

void *memcpy(void *dest, const void *src, size t n)


n src dest; src dest (. memmove); dest

mem.h

memicmp

int memicmp(const void *sl, const void *s2, size_t n)


, ( ), n si s2; < 0 si < s2, = 0
si = s2, > 0 si > s2

mem.h

265

, C++, C++Builder, API Windows

memmove

void *memmove(void *dest, const void *src, size t n)


src dest; src dest (. ); dest

mem.h

void *memset(void *s, int , size_t n)


n s ; s

mem.h

setmem

void setmem(void *dest, unsigned length, char value)


dest length value

mem.h

, , , .
3.4.2.2

AnsiStr
Comp

/
int AnsiStrComp(char * SI, char * S2)
SysUtils.hpp
81 S2 ;
< 0 SI < S2, = 0 SI = S2, > 0 SI > S2

AnsiStr
IComp

int AnsiStrIComp(char * SI, char * S2)


SysUtils.hpp
81 S2 ; < 0 SI < S2, = 0 SI = S2, > 0 SI > S2

AnsiStr
LComp

int AnsiStrLComp(char * SI, char * S2,


SysUtils.hpp
Cardinal MaxLen)
MaxLen 81 S2; < 0 SI < S2, = 0 SI = S2, > 0 SI > S2

AnsiStrLI
Comp

int AnsiStrLIComp(char * SI, char * S2,


SysUtils.hpp
Cardinal MaxLen)
MaxLen 81 S2
; < 0 SI < S2, = 0
SI = S2, > 0 SI > S2

char * AnsiStrLower(char * Str)


,

AnsiStrPos char * AnsiStrPos(char * Str, char * SubStr)
SubStr
Str NULL
char * AnsiStrRScan(char * Str, char Chr)
AnsiStr
RScan
Chr Str NULL

SysUtils.hpp

char * AnsiStrScan(char * Str, char Chr)



Chr Str NULL

SysUtils.hpp

AnsiStr
Lower

AnsiStr
Scan

SysUtils.hpp

SysUtils.hpp

266

AnsiStr
Upper

char * AnsiStrUpper(char * Str)


,

SysUtils.hpp

CharTo
Oem

BOOL CharToOem(LPCTSTR IpszSrc, LPSTR IpszDst) winuser.h


MS-DOS

OemBuff

BOOL CharToOemBuff(LPCTSTR IpszSrc,


winuser.h
LPSTR IpszDst, DWORD cchDstLength)
MS-DOS

Compare
Str

int CompareStr(const System::AnsiString SI,


SysUtils.hpp
const System::AnsiString S2)
81 S2 ;
< 0 SI < S2, = 0 SI = S2, > 0 SI > S2

Compare
Text

int CompareText(const System::AnsiString SI,


SysUtils.hpp
const System::AnsiString S2)
81 S2 ; < 0 SI < S2, = 0 SI = S2,.> 0 SI > S2

LineStart

char * LineStart(char * Buffer, char * BufPos)



Buffer, BufPos

SysUtils.hpp

mbscpv

unsigned char * mbscpy(unsigned char *dest,


mbstring.h
const unsigned char *src)
src dest

mbslwr

unsigned char * mbslwr(unsigned char *s)


mbsncpv

unsigned char * mbsncpy(unsigned char *dest,


mbstring.h
const unsigned char *src, size_t maxlen)
maxlen src dest

mbsupr

unsigned char * mbsupr(unsigned char *s)


Char

mbstring.h

mbstring.h

BOOL OemToChar(LPCTSTR IpszSrc, LPSTR IpszDst) winuser.h


MS-DOS

OemTo
CharBuff

BOOL OemToCharBuff(LPCTSTR IpszSrc,


winuser.h
LPSTR IpszDst, DWORD cchDstLength)
MS-DOS

StrAlloc

char * StrAlloc(Cardinal Size)


Size 1 ;
StrDispose

SysUtils.hpp

StrBufSize Cardinal StrBufSize(char * Str)


,
StrAlloc
Str

SysUtils.hpp

267

, C++, C++Builder, API Windows

strcat

StrCat

strchr

strcmp

strcmpi

StrComp

StrCopv
strcpy
strcspn

strdup

StrECopy

StrEnd

strerror

/
char *strcat(char *dest, const char *src)
src dest;
char * StrCat(char * Dest, char * Source)
Source Dest;
char *strchr(const char * s, int )
C B S ,
NULL
int strcmp(const char *sl, const char *s2)
si s2; < 0 si < s2,
= 0 si = s2, > 0 si > s2
int strcmpi(const char *sl, const char *s2)
To , stricmp: si s2
( ); < 0
si < s2, = 0 si = s2, > 0 si > s2
int StrComp(char * Strl, char * Str2)
81 S2 ( AnsiStrComp);
< 0 SI < S2, = 0 SI = S2, > 0 SI > S2
char * StrCopy(char * Dest, char * Source)
Source Dest Dest
char *strcpy(char *dest, const char *src)
src dest; dest
size_t strcspn(const char *sl, const char *s2)
si, s2
char *strdup(const char *s)
s;
char * StrECopy(char * Dest, char * Source)
Source Dest
Dest
char * StrEnd(char * Str)

Str
char *strerror(int errnum)
errnum

string.h

SysUtils.
hpp
string.h

string.h

string.h

SysUtils.hpp

SysUtils.hpp
string.h
string.h

string.h

SysUtils.hpp

SysUtils.hpp

string.h

268

stricmp

StrlComp

StrLCat

StrLComp

StrLCopv

strlen

/
int stricmp(const char *sl, const char *s2)
To , strcmpi: si s2
( ); < 0
si < s2, = 0 si = s2, > 0 si > s2
int StrIComp(char * Strl, char * Str2)
81 S2 ( AnsiStrlComp);
< 0 SI < S2, = 0 SI = S2, > 0 SI > S2
char * StrLCat(char * Dest, char * Source,
Cardinal MaxLen)
MaxLen Source
Dest Dest
int StrLComp(char * Strl, char * Str2,
Cardinal MaxLen)
MaxLen 81 S2 (
AnsiStrLComp); < 0 SI < S2, = 0
SI = S2, > 0 SI > S2
char * StrLCopy(char * Dest, char * Source,
Cardinal MaxLen)
MaxLen Source Dest Dest

size_t strlen(const char *s)


s,

Cardinal StrLen(char * Str)
StrLen
Str,

StrLIComp int StrLIComp(char * Strl, char * Str2,
Cardinal MaxLen)
MaxLen 81 S2
(
AnsiStrLIComp); < 0 SI < S2, = 0
SI = S2, > 0 SI > S2
StrLower
char * StrLower(char * Str)
,
( AnsiStrLower);
strlwr
char *strlwr(char *s)
s ( )
StrMove
char * StrMove(char * Dest, char * Source,
Cardinal Count)
Count Source Dest Dest; Source Dest

string.h

SysUtils.hpp

SysUtils.hpp

SysUtils.hpp

SysUtils.hpp

string.h

SysUtils.hpp

SysUtils.hpp

SysUtils.hpp

string.h

SysUtils.hpp

. C++, C++Builder, API Windows

strncat

strncmp

269

char *strncat(char *dest, const char *src,


string.h
size_t maxlen)
maxlen src dest ; dest

hit strncmp(const char *sl, const char *s2,


size_t maxlen)
maxlen si s2; < 0 si < s2, = 0 si = s2, > 0 si > s2
strncmpi
int strncmpi(const char *sl, const char *s2, size_t n)
To , strnicmp: maxlen
si s2 ( ); < 0 si < s2, = 0 si = s2, > 0 si > s2
strncpy
char *strncpy(char *dest, const char *src,
size_t maxlen)
maxlen src dest; dest
StrNew
char * StrNew(char * Str)
Str
strnicmp
int strnicmp(const char *sl, const char *s2,
size_t maxlen)
To , strncmpi: maxlen
si s2 ( ); < 0 si < s2, = 0 si = s2, > 0 si > s2
char *strnset(char *s, int ch, size_t n)
strnset
ch n s
char *strpbrk(const char *sl, const char *s2)
strpbrk
si s2 NULL
StrPCopy char * StrPCopy(char * Dest,
const System::AnsiString Source)
Source Dest Dest
StrPLCopy char * StrPLCopy(char * Dest,
const System::AnsiString Source, Cardinal MaxLen)
MaxLen Source Dest
Dest
char * StrPos(char * Strl, char * Str2)
StrPM
Str2 Strl
NULL
char *strrchr(const char *s, int c)
strrchr
C B S
NULL

string.h

string.h

stdio.h

SysUtils.hpp

string.h

string.h
string.h

SysUtils.hpp

SysUtils.hpp

SysUtils.hpp

string.h

270

strrev

StrRScan

StrScan

string.h
char *strrev(char *s)
() s
SysUtils.hpp
char * StrRScan(char * Str, char Chr)
Chr Str
NULL
char * StrScan(char * Str, char Chr)
SysUtils.hpp
Chr Str
NULL

strset

char *strset(char *s, int ch);


string.h
s ch

strspn

size_t strspn(const char *sl, const char *s2)


string.h
si, s2 ( )

strstr

char *strstr(const char *sl, const char *s2)


s2
si NULL

strtok

char *strtok(char *sl, const char *s2)


string.h
s2
si si;

StrUpper

char * StrUpper(char * Str)


,
( AnsiStrUpper);

SysUtils.hpp

strupr

char *strupr(char *s)


s ( )

string.h

wcslwr

wchar t * wcslwr(wchar t *s)


s

string.h

wcsupr

wchar t * wcsupr(wchar t *s)


s

string.h

string.h

string.h, (strcmpi, stricmp,


strlwr, strncmpi, strnicmp, strupr), , . SysUtils.hpp.
.
, , , . .
strcat , , , .
,

, C++, C++Builder, API Windows

271

. strcat, . strcpy , ,
, . strstr . strcat,
strcpy, strstr strlen . 2, . 2.5.1.
strtok, .
si
, s2. , , .. si .
si.
strtok, NULL. si ( s2
), s2,
. , .
.
char s [ 8 0 ] , *;
= strtok(s, " , . ") ;
if (p) Memol->Lines->Add(p);
while(p)
{
p = strtok(NULL, " ,.;");
if (p) Memol->Lines->Add(p);
}

s : , , . Momol. ,
s ' " , .", Memol :

strtok ,
:

LineStart Buffer
BufPos "\". ,
, .
BufPos , 1 , .. "\" ,
Buffer. , "
char *Buf = " \ \ ",
* = StrEnd(Buf);
do
{
P=LineStart(Buf , P-l) ;

} w h i l e ( P != B u f ) ;
, , Buf.

272

3.4.2.3 AnsiString

AdjustLine
Breaks

SysUtils.hpp
System::AnsiString AdjustLineBreaks(
const System::AnsiString S)
S
CR/LF Unix

AnsiCompare
Sir

int AnsiCompareStr(const System::AnsiString SI, SysUtils.hpp


const System::AnsiString S2)
81 S2 ;
< 0 SI < S2, = 0 SI = S2, >
SI > S2

AnsiCompare
Text

SysUtils.hpp
int AnsiCompareText(
const System::AnsiString SI,
const System::AnsiString S2)
81 S2 ;
< 0 SI < S2, = 0 SI = S2, >
SI > S2

AnsiExtract
QuotedStr

System::AnsiString AnsiExtractQuotedStr(
SysUtils.hpp
char * &Src, char Quote)
Src ,
Quote,

AnsiLowerCase

System::AnsiString AnsiLowerCase(
const System::AnsiString S)
S,
( )

SysUtils.hpp

AnsiPos

int AnsiPos(const System::AnsiString Substr,


const System::AnsiString S)
Substr
S

SysUtils.hpp

AnsiQuotedStr

System::AnsiString AnsiQuotedStr(
SysUtils.hpp
const System::AnsiString S, char Quote)
S ,
Quote,

AnsiUpperCase

System::AnsiString AnsiUpperCase(
SysUtils.hpp
const System::AnsiString S)
S,
( )

IsDelimiter

bool IsDelimiter(
SysUtils.hpp
const System::AnsiString Delimiters,
const System::AnsiString S, int Index)
, Index S , Delimiters

, C++, C++Builder, API Windows

IsPathDelimiter bool IsPathDelimiter(const System::AnsiString S,


int Index);
, Index S '\',

273

SysUtils.hpp

LastDelimiter

int LastDelimiter(
SysUtils.hpp
const System::AnsiString Delimiters,
const System-AnsiString S)

S ,
Delimiters

LowerCase

System::AnsiString LowerCase(
const System::AnsiString S)
S,
( AnsiLowerCase)

QuotedStr

System::AnsiString QuotedStr(
SysUtils.hpp
const System::AnsiString S)
S

( AnsiQuotedStr)

StringReplace

System::AnsiString StringReplace(
SysUtils.hpp
const System::AnsiString S,
const System::AnsiString OldPattern,
const System::AnsiString NewPattern,
TReplaceFlags Flags)
S OldPattern NewPattern; Flags

Trim

System-AnsiString Trim(
SysUtils.hpp
const System::AnsiString S)
S

TrimLeft

System::AnsiString TrimLeft(
SysUtils.hpp
const System::AnsiString S)
S

TrimRight

System-AnsiString TrimRight(
const System::AnsiString S)
S

SysUtils.hpp

SysUtils.hpp

274

UpperCase

SysUtils.hpp
System::AnsiString UpperCase(
const Systeni::AnsiStrmg S)
S,
( AnsiTJpperCase)

WrapText

System::AnsiString WrapText(
SysUtils.hpp
const System::AnsiString Line,
const System::AnsiString BreakStr,
const TSysCharSet &BreakChars,
int MaxCol)
Line, MaxCol BreakStr BreakChars

, , . 3.1.6
AnsiString.
AnsiString.
, AnsiString, ,
. , -.
char *.
.
IsDelimiter IsPathDelimiter 1 ( C++Builder). 1 , 2 ..
IsDelimiter
- . ,
A n s i S t r i n g S, Delimiters;
Delimiters = " ' " ;
S =
f o r (int i = 1; i <= StrLen (S . c_str () ) ; 1++)
if (IsDelimiter (Delimiters, S, i) )

S .
Delimiters . . , :
A n s i S t r i n g S, Delimiters;
Delimiters = " 1 2 3 4 5 6 7 8 9 " ;
S =
for (int i = 1; i <= StrLen (S . c_str ( ) ) ; i++)
if (IsDelimiter (Delimiters, S, i) )
S[i] -= 1;

, 0, 1.
StringReplace S OldPattern
NewPattern. Flags rfReplaceAH,
OldPattern. Flags
rflgnoreCase, . ,
31 = StringReplace (S, O l d P a t t e r n , N e w P a t t e r n ,
TReplaceFlags ( ) rfReplaceAH) ;

, C++, C++Builder, API Windows

275

S1 S OldPattern
NewPattern.
WrapText Line . , BreakStr. MaxCol .
BreakStr ,
BreakChars.
, MaxCol.
BreakChars ,
MaxCol. ,
TSysCharSet bchars;
bchars ' ' ' . ' ' , ' ' ; ' ' + ' '-';
AnsiString S, SI;
S =
SI = W r a p T e x t ( S , " V n \ r " , bchars, 10);

SI S, 10 ,
. S : " ,
+ -.", :
" "
" "
" "
" ,"
""
" "
"- "
" +"
" -."

, 11 , ,
.. .
,
. . .

3.5
3.5.1 ,
, dos.h:
FA_RDONLY

FA_HIDDEN

FA_SYSTEM

FAJLABEL

FA_DIREC

FA_ARCH

. 3.5.6.
(|).

276

( fcntl.h):

WRONLY

RDWR


, 0

RDONLY

CREAT
TRUNC
BINARY
TEXT
NOINHERIT

NDELAY
O_APPEND
0_CREA

O_EXCL




, UNIX
,

, ,
, mode, ,
O_CREA , ,
,

mode (
sys\stat.h):
S IWRITE
S IREAD
S_IREAD S_IWRITE

( share.h):
SH_COMPAT

SH_DENWR
SH_DENYNO
SH_DENYNONE
SH_DENYRD
SH_DENYRW

. (, SH_COMPAT | SH_DENWR).
,
,
(
SH_DENYNONE )
. , SH_COMPAT
,

, C++, C++Builder, API Windows

277

(|).
SH_DENYRD, SH_DENYNO .
,
(
SysUtils.hpp):

fmOpenRead

$0000
$0001

fmOpenReadWrite
fmShareCompat

$0002


FCB

fmShareExclusive

$0010

fmOpen Write

$0000

fmShareDeny Write $0020


fmShareDenyRead

$0030

fmShareDenyNone

$0040

C++ (stream),
.
C++Builder .
, ()
FILE, stdio.h, . (handle) ,
.

:

stdin

stdout
stderr

.
, ,
Windows.

3.5.2 ,
FILE
, FILE, .

278

_fdopen

_fileno
_flushall

/
stdio.h
FILE *_fdopen(int handle, char * mode)
handle,
mode,
FILE NULL
stdio.h
int _fileno(FILE *stream)
stream
stdio.h
int _flushall(void)
, ;

_fsopen

FILE * fsopen(const char *filename, const char *mode,


stdio.h,
int shflag) share.h
filename , shflag mode;
FILE NULL

fclose

int fclose(FILE *stream)


stream

fflush

stdio.h
int fflush(FILE *stream)
stream,
; 0 EOF
FILE *fopen(const char *filename, const char *mode)
stdio.h
filename mode

FILE NULL

fopen

stdio.h

freopen

FILE *freopen(const char *filename, const char *mode,


stdio.h
FILE *stream)
stream
filename mode FILE NULL

setbuf

void setbuf(FILE *stream, char *buf)


stdio.h
buf stream

int setvbuf (FILE *stream, char *buf, int type, size_t size) stdio.h
buf size stream

FILE *tmpfile(void)
stdio.h

FILE NULL

setvbuf

tmpfile

fopen, filename. mode , . :

, C++, C++Builder, API Windows

r+

+
w
W+

279





; ,

;
,

"+" "t" , "" , . , "rt", "rb", "r+t", "r+b" .. "t", "" ,


_fmode, fcntl.h. _ ( ) O_BINARY .
, fopen
FILE. , NULL. :
FILE *F;
if ( (F = fopen ("Test.txt", "rt")) == NULL)
{
ShowMessage(" ");
return;
}

, , , .
. ,
fseek rewind, . 3.5.4. , :
() () fseek rewind
fseek rewind

_fsopen filename , shflag mode. , shflag, . . 3.5.1. mode
fopen.
DOS SHARE.EXE.
freopen stream
filename mode. fopen ,
stream . , ,
. ,
FILE *F = f r e o p e n ( " o u t p u t . t x t " , " w t " , s t d o u t ) ;

stdout "output.txt". stdout .

280

_fdopen , ( . . 3.5.3), FILE. ,


FILE * stream = fdopen(handle, " w " ) ;

handle stream.
- - ,
FILE, _fileno.
"Test.txt" .
FILE *stream;
int handle;
stream = f o p e n ( " T e s t . t x t " , " w " ) ; //
handle = _ f i l e n o ( s t r e a m ) ;
//
fclose(stream);

//

, ..
, , .
, ,
fflush _flushall. , . ,
, .
.
.
setbuf setvbuf.
setbuf buf NULL,
. ,
, . buf
,
stream .
BUFSIZ, stdio.h. :
char outbuf[BUFSIZ];
setbuf(F, outbuf);

setbuf fseek (. . 3.5.4),


. setbuf .
setvbuf
. buf = NULL
malloc
size.'
.
UINT_MAX, limits.h.
type :
IOFBF

. ,
. , .

, C++, C++Builder, API Windows

_IOLBF

_IONBF

281

. ,
, , . , .
/. buf size
.

setvbuf 0.
, fopen freopen, fclose. .
setbuf setvbuf buf NULL, .
tmpfile
(w+b) FILE. NULL.
, .
, FILE,
. . 2 . 2.10.2.

3.5.3 ,

.
/
int _creat(const char *path, int mode)

mode; 1
_rtl_close int _rtl_close(int handle)
handle
_rtl_creat int _rtl_creat(const char *path, int attrib)

path attrib; -1

_rtl_open int _rtl_open(const char *filename, int oflags)


filename
oflags; -1
int _sopen(char *path, int access, int shflag [, int mode])
_sopen
path , access, shflag, mode;
-1
int close(int handle)
close
handle
creatnew int creatnew(const char *path, int attrib)
_rtl_creat, ,

io.h, dos.h

_creat

io.h,
sys\stat.h
io.h

io.h, dos.h

fcntl.h,
sys\stat.h,
share.h, io.h,
stdio.h
io.h

io.h, dos.h

282

/
creattemp int creattemp(char *path, int attrib)
attrib path

io.h, dos.h

dup

int dup(int handle)


handle

io.h

dup2

int dup2(int oldhandle, int newhandle)


newhandle oldhandle

io.h

FileClose

void FileClose(int Handle)


Handle

SysUtils.hpp

FileCreate int FileCreate(const System::AnsiString FileName)


FileName
1

SysUtils.hpp

FileOpen

int FileOpen(const System::AnsiString FileName,


SysUtils.hpp
int Mode)
FileName Mode -1

lock

int lock(int handle, long offset, long length)


handle length ,
offset

io.h

locking

int locking(int handle, int cmd, long length)


handle length
,

io.h, sys\locking.h

setmode

int setmode(int handle, int amode)


io.h
amode
handle:
O_BINARY , OJTEXT

umask

unsigned umask(unsigned mode)


io.h
/ mode, open creat:
S_IWRITE, S_IREAD S_IREAD|S_I WRITE;

unlock

int unlock(int handle, long offset, long length)


io.h
handle length ,
offset,

_creat mode. path .


, _fmode _ O_BINARY. , 0.

, C++, C++Builder, API Windows

283

, _creat , .
, , mode, , sys\stat.h . 3.5.1.
.
-1, (. . 3.1.4.1) EACCES, ENOENT, EMFILE.
_creat _rtl_creat. _creat, attrib (|) : FA_RDONLY , FA_HIDDEN , FA_SYSTEM ( . . 3.5.1).
creatnew _rtl_creat , ,
-1 , .
_rtl_open filename
oflags. .
3.5.1.
. 1, (. . 3.1.4.1) EINVACC, EACCES, ENOENT, EMFILE.
_sopen path , access, shflag, mode. access _...
, . 3.5.1. O_CREA,
mode (. . 3.5.1).
shflag .
. 3.5.1.
. -1, (. . 3.1.4.1) EINVACC, EACCES, ENOENT, EMFILE.
creattemp attrib path. ,
_fmode (O_TEXT O_BINARY).
attrib
FA_HIDDEN, FA_RDONLY FA_SYSTEM (. . 3.5.1).
, HANDLE_MAX.
close, _rtl_close FileClose , creat, creatnew, creattemp, dup, dup2, open, _rtl_creat, _rtl_open, FileOpen.
Qrl-Z. , .
0. -1 (. . 3.1.4.1) EBADF.
, , , :
int hout = open("output.txt", OJ3REAT I 0_WRONLY,S_IWRITE);

close(hout);
,
int handle;
if ((handle = open ("Test.txt", 0_CREAT | 0_TEXT)) == -1)
{
ShowMessage(" ");

284
return;
close (handle) ;

, ( open -1) .
FileOpen, FileCreate FileClose , . FileOpen Mode, fmShare (. . 3.5.1).
FileRead,
FileWrite, FileSeek, . 3.5.4.

lock, unlock, locking. DOS SHARE.EXE.
locking cmd:
LK _LOCK
LK _RLCK
LK _NBLCK
LK _NBRLCK
LK _UNLCK

. , , , 10 .
, LK_LOCK.
. ,
.
, LK_NBLCK.
.

0. -1, (. . 3.1.4.1) EACCES,


EBADF, EDEADLOCK , 10 ( cmd LK_LOCK LK_RLCK), EINVAL cmd SHARE.EXE.
dup dup2 . dup () handle. , , ( , , )
. . dup2 dup newhandle oldhandle. dup dup2 , ,
. ,
int hout = open ( " o u t p u t . t x t " , 0_CREAT I 0 WRONLY,S I W R I T E ) ;
dup2(hout,1);

stdout ( 1 . . 3.5.1) "output.txt".

3.5.4 /

fgetchar

int fgetchar(void)
stdin

stdlo.h

, C++, C++Builder, API Windows

feetwchar wint t fgetwchar(void)


stdin
fuutchar

285

stdio.h

int fputchar(int )
stdio.h
stdout, , fputc(c,
stdout); EOF

fputwchar wint t fputwchar(int )


stdio.h
stdout, , fputc(c,
stdout); EOF
_getw
int _getw(FILE *stream)
stdio.h
stream

-"*"

wchar_t *_getws(wchar_t *s)


stdio.h
stdin

cgets

char *cgets(char *str)


conio.h

clearerr

void clearerr(FILE *stream)



stream

stdio.h

cprintf

int cprintf(cbnst char *format [, argument, ...]


argument no
format (. . 3.1.3.1)

conio.h

cputs

int cputs(const char *str)


;

conio.h

cscanf

int cscanf(char *format [, address, ...])


conio.h
argument format;
EOF

eof

int eof(int handle)


io.h
0 (),
handle

feof

int feof(FILE *stream)


0 ()
stream

stdio.h

ferror

int ferror(FILE *stream)


/ stream
0

stdio.h

fgetc

int fgetc(FILE *stream)


stdio.h
stream
stdio.h
int fgetpos(FILE *stream, fpos_t *pos)
pos stream;
0

fgetpos

286

fgets

FileRead

FileSeek

FileWrite

fprintf

/
char *fgets(char *s, int n, FILE *stream)
s n stream
int FileRead(int Handle, void *Buffer, int Count)
Handle, FileOpen FileCreate, Count Buffer;
1
int FileSeek(int Handle, int Offset, int Origin)
Handle, FileOpen FileCreate,
Offset Origin; 0

stdio.h

SysUtils.hpp

SysUtils.hpp

int FileWrite(int Handle, const void *Buffer, int Count) SysUtils.hpp


Handle,
FileOpen FileCreate, Count
Buffer; -1
int fprintf(FILE *stream, const char *format [, argu- stdio.h
ment, ...])
stream argument
format; EOF

fputc

int fputc(int , FILE *stream)


stream

stdio.h

fputs

int fputs(const char *s, FILE *stream)


s stream; EOF

stdio.h

fputwc

wint_t fputwc(wint_t c, FILE *stream)


stream

stdio.h

fputws

int fputws(const wchar_t *s, FILE *stream)


s stream; EOF

stdio.h

fread

size_t fread(void *ptr, size_t size, size_t n,


stdio.h
FILE *stream)
stream ptr n size ;
(n * size)

fscanf

int fscanf(FILE *stream,


stdio.h
const char *format [, address, ...])
stream
argument format;
EOF

, C++, C++Builder, API Windows

fseek

287

int fseek(FILE *stream, long offset, int fromwhere)


stdio.h
stream offset
fromwhere; 0

fsetpos

int fsetpos(FILE *stream, const fpos_t *pos)


stdio.h
stream pos

ftell

long int ftell(FILE *stream)


stream

fwrite

size_t fwrite(const void *ptr, size t size, size t n,


stdio.h
FILE *stream)
ptr stream n size ;
(n * size)

getc

int getc(FILE *stream)


stream

stdio.h

getch

int getch(void)

conio.h

getchar

int getchar(void)
stdin; , getc(stdin)

stdio.h

getche

int getche(void)

conio.h

getpass

char *getpass(const char *prompt)



prompt;

conio.h

gets

char *gets(char *s)


stdin

stdio.h

kbhit

int kbhit(void)
conio.h
;
0
long lseek(int handle, long offset, int fromwhere)
io.h
handle
offset fromwhere; 0

Iseek

stdio.h

stdio.h

perror

void perror(const char *s)


s

printf

stdio.h
int printf(const char *format [, argument, ...])
stdout argument format (. . 3.1.2.1)
stdio.h
int putc(int , FILE *stream)
stream

putc

288

putch

int putch(int c)

conio.h

putchar

stdio.h
int putchar(int )
, stdout;
putc(c, stdout)
stdio.h
int puts(const char *s)
s stdout '

stdio.h
int _putws(const wchar_t *s)
s stdout

puts

_putws

puttext

conio.h
int puttext(int left, int top, int right, int bottom,
void *source)
source
left, top, right, bottom

putw

int _putw(int w, FILE *stream)


stream w

stdio.h

read

int read(int handle, void *buf, unsigned len)


handle buf
len

io.h

scanf

int scanf(const char *format [, address, ...])


stdin
argument format (. .
3.1.3.2)

stdio.h

sprintf

int sprintf(char *buffer,


conio.h
const char *format [, argument, ...])
buffer argument format (. . 3.1.3.1)

sscanf

int sscanf(const char *buffer,


conio.h
const char *format [, address, ...])
buffer
argument format

tell

long tell(int handle)


io.h

handle

ungetc

int ungetc(int , FILE *stream)


stdio.h
ch stream,

ungetch

int ungetch(int ch)


conio.h
ch ,

289

, C++, C++Builder, API Windows

vfprintf

int vfprintf(FILE *stream, const char *format,


stdio.h
va_list arglist)
stream arglist no
format (. . 3.1.3.1)

vfscanf

int vfscanf(FILE *stream, const char *format,


stdio.h
va_list arglist)
stream arglist format (. . 3.1.3.2)

vprintf

int vprintf(const char *format, va_list arglist)


stdout arglist format (. . 3.1.3.1)

stdarg.h

vscanf

int vscanf(const char *format, va_list arglist)


stdin arglist format (. . 3.1.3.2)

stdarg.h

vsprintf

int vsprintf(char *buffer, const char *format,


stdarg.h
va_list arglist)
buffer arglist
format (. . 3.1.3.1)

vsscanf

int vsscanf(const char *buffer, const char *format,


stdarg.h
va_list arglist)
buffer arglist format (. . 3.1.3.2)

write

int write(int handle, void *buf, unsigned len)


handle
buf len

io.h

scanf
printf .
printf, sprintf, vfprintf, vprintf, vsprintf . . 3.1.3.1. EOF .
fscanf, scanf, cscanf, sscanf, vfscanf, vscanf, vsscanf
. . 3.1.3.2.
getchar, _fgetchar, cgets, cprintf, _fputchar, putch, puttext, getch,
getche, cputs, getpass, cscanf, kbhit, ungetc, ungetch, vprintf, vscanf Win32.
Win32
scanf, gets stdin,
printf, putchar, puts stdout.
getchar, _fgetchar, getc, fgetc , .
getchar, _fgetchar, getc, gets, fgets, fgetc, fputc EOF.

290

getc, fgetc, getchar .


getc 1, .
_getw , . () . putw, puts .
EOF. EOF
,
feof ferror.
gets ,
, .
fgets , ,
.
puttext, ,
, source, left, top, right, bottom. (1,1). 2 ,
, . 0 .
fseek Iseek offset fromwhere. offset 0 , ftell.
fromwhere, ,
offset, :
SEEK_SET

SEEK_CUR
SEEK END

0 .
FileRead, File Write FileSeek ,
FileOpen FileCreate.

3.5.5

_mktemp

/
.
char *_mktemp(char *template)
dir.h
, template ,

ChangeFileExt System::AnsiString ChangeFiIeExt(
SysUtils.hpp
const System::AnsiString FileName,
const System::AnsiString Extension)
FileName
Extension;

291

, C++, C++Builder, API Windows

ExpandFile
Name

ExpandUNC
FileName

ExtractFileDir

ExtractFile
Drive

ExtractFileExt

ExtractFile
Name

ExtractFile
Path

Extract
RelativePath

ExtractShort
PathName

MatchesMask

/
System: :AnsiString ExpandFileName(
const System::AnsiString FileName)
FileName,
;
System::AnsiString ExpandUNCFileName(
const System::AnsiString FileName)
FileName,
UNC:
"\\<servername>\<sharename>",
System::AnsiString ExtractFileDir(
const System::AnsiString FileName)
FileName
System::AnsiString ExtractFileDrive(
const System::AnsiString FileName)
FileName (,
":") UNC: "\\<servername>\<sharename>",
System::AnsiString ExtractFileExt(
const System::AnsiStrmg FileName)
FileName
System::AnsiString ExtractFileName(
const System::AnsiString FileName)
, FileName,
..
System::AnsiString ExtractFilePath(
const System::AnsiString FileName)
, FileName,
,
System::AnsiString ExtractRelativePath(
const System::AnsiString BaseName,
const System::AnsiString DestName)
DestName BaseName,
"..\"
System::AnsiString ExtractShortPathName(
const System::AnsiString FileName)
FileName, 8.3
bool MatchesMask(
const System::AnsiString Filename,
const System::AnsiString Mask)
Filename Mask

SysUtils.hpp

SysUtils.hpp

SysUtils.hpp

SysUtils.hpp

SysUtils.hpp

SysUtils.hpp

SysUtils.hpp

SysUtils.hpp

SysUtils.hpp

Masks.hpp

292

filectrl.hpp
MinimizeName System: :AnsiString MinimizcName(
const System:: AnsiString Filename,
Graphics: :TCanvas * Canvas, int MaxLen)
Filename,
,
Canvas MaxLen
ProcessPath

tmpnam

void ProcessPath(
filectrl.hpp
const System::AnsiString EditText,
char &Drive, System::AnsiString &DirPart,
System::AnsiString &FilePart)
EditText
Drive, DirPart FilePart
char *tmpnam(char *s)
stdio.h
,

( tmpnam _mktemp) AnsiString


(. . 2.5.2 3.1.7),
FileName. . FileName , ExtractFile... .
,
. :
"C:\\Program Files\\Bcb.exe"

ExtractFileDir ,
CreateDir, GetCurrentDir, RemoveDir, SetCurrentDir
(. . 3.5.6).
ExtractShortPathName FileName, 8.3. ,
:\Program Files\Borland\CBuilder\Bin\Bcb.exe

:\Progra~l\Borland\CBuilder\Bin\Bcb.exe

MatchesMask Filename Mask.


- , , "*" "?" . [ ]. <>-<>. ,
"-". "!", , .
. MatchesMask true,
Filename , false, . ,
"[a-b]:\\test\\*.*"

, : :
"test".

, C++, C++Builder, API Windows

293

MinimizeName Filename, , Canvas MaxLen . . ,


Labell->Caption = MinimizeName(":\\Program Files\\Bcb.exe",
Labell->Canvas, 1 0 0 ) ;

Labell :
:\...\Bcb.exe
tmpnam _mktemp ,
.
tmpnam _ = 65 535 . s NULL,
L_tmpnam ( stdio.h). NULL, tmpnam .
, tmpnam
_mktemp, . .

3.5.6

_getdcwd

char * _getdcwd(int drive, char *buffer, int buflen) direct.h


buffer buflen
drive (0 , 1
..); buffer NULL;
buffer = NULL

_rmdir

int _rmdir(const char *path)


dir.h
path (,
); 0 -1
int _rtl_chmod(const char *path, int func [,
io.h, dos.h
int attrib])
func = 0 ,
func = 1 attrib

_rtl_chmod

int _unlink(const char *filename)


filename; 0 -1
int _waccess(const wchar_t *filename, int amode)
_waccess
, filename
;
amode
_wrtl_chmod int _wrtl_chmod(const wchar_t *path, int func, ... )
func = 0 ,
func = 1 attrib
int access(const char ^filename, int amode)
access
, filename
;
amode

_unlink

io.h
io.h

io.h, dos.h

io.h

294

chdir

/
int chdir(const char *path)
path ; 0 -1

dir.h

chmod

io.h
int chmod(const char *path, int amode)
amode path; 0 1; amode
S_IWRITE S_IREAD

chsize

int chsize(int handle, long size)


io.h
handle, , size ; 0
-1
bool CreateDir(const System::AnsiString Dir)
SysUtils.hpp
Dir true

CreateDir

DeleteFile

Directory
Exists

bool DeleteFile(const System::AnsiString FileName) SysUtils.hpp


FileName true

bool DirectoryExists(const System::AnsiString Name) SysUtils.hpp
, Name

DiskFree

int DiskFree(Byte Drive)


SysUtils.hpp
Drive
-1, Drive (Drive =0 , 1 , 2 ..)

DiskSize

int DiskSize(Byte Drive)


SysUtils.hpp
Drive -1,
Drive (Drive =0 ,
1 , 2 ..)

FileAge

int FileAge(const System: :AnsiString FileName)


SysUtils.hpp
FileName -1,

FileDateTo
DateTime

System::TDateTime FileDateToDateTime(
SysUtils.hpp
int FileDate)
TDateTime
FileDate, DOS

FileExists

bool FileExists(const System::AnsiString FileName) SysUtils.hpp


, FileName

FileGetAttr

int FileGetAttr(const System::AnsiString FileName) SysUtils.hpp


FileName

FileGetDate

int FileGetDate(int Handle)



Handle -1,

SysUtils.hpp

, C++, C++Builder, API Windows

filelength

FileSearch

FileSetAttr

FileSetDate

FindClose

FindFirst

findfirst

wfindfirst

FindNext

findnext

wfindnext

/
long filelength(int handle)

handle; -1
System::AnsiString FileSearch(
const System:: AnsiString Name,
const System::AnsiString DirList)
DirList Name;
hit FileSetAttr(const System::AnsiString FileName,
int Attr)
FileName Attr; 0
int FileSetDate(int Handle, int Age)
Age
Handle; 0
void FindClose(TSearchRec &F)

FindFirst FindNext F
int FindFirst(const System::AnsiString Path,
int Attr, TSearchRec &F)
Path Attr; F; 0

int findfirst(const char FAR * path,
struct ffblk _FAR * ffblk, int
attrib)
path attrib; ffblk; 0 -1
int wfindfirst(const wchar t *pathname,
struct _wffblk *ffblk, int attrib)
pathname attrib; _wffblk; 0 -1
int FindNext(TSearchRec &F)
, FindFirst F; F; 0
int findnext(struct ffblk FAR *
ffblk)
, findfirst
ffblk; 0
-1
int wfindnext(struct wffblk *ffblk)
,
_wfindfirst ffblk; 0
-1

295

io.h

SysUtils.hpp

SysUtils.hpp

SysUtils.hpp
SysUtils.hpp

SysUtils.hpp

dir.h

dir.h

SysUtils.hpp

dir.h

dir.h

296

/
void fnmerge(char *path, const char *drive,
const char *dir, const char *name,
const char *ext)
path : drive, dir,
name ext
int fnsplit(const char *path, char *drive, char *dir,
char *name, char *ext)
path : drive, dir,
name ext
void ForceDirectories(System::AnsiString Dir)
Dir ,

fstat

int fstat(int handle, struct stat *statbuf)


statbuf handle;
0 -1

sys\stat.h

getcurdir

int getcurdir(int drive, char *directory)


dir.h
directory drive
(0 , 1 ..)
"\"

GetCurrent
Dir

System::AnsiString GetCurrentDir()

getcwd

char *getcwd(char *buf, int buflen)


dir.h
buf
buflen ,
; buf NULL;
buf = NULL

getdisk

int getdisk(void)
: 0 , 1 ..

dir.h

getftime

int getftime(int handle, struct ftime *ftimep)


handle
ftimep; 0 -1

io.h

GetSystem
Directory

UINT GetSystemDirectory(LPTSTR IpBuffer,


UINT uSize)
API Windows, IpBuffer
uSize Windows

GetWindows
Directory

UINT GetWindowsDirectory(LPTSTR IpBuffer,


UINT uSize)
API Windows, IpBuffer
uSize Windows

fnmerge

fnsplit

Force
Directories

dir.h

dir.h

FileCtrl.hpp

SysUtils.hpp

, C++, C++Builder, API Windows

297

isatty

int isatty(int handle)


, handle : , , ,

io.h

mkdir

int mkdir(const char *path)


dir.h
path; 0 -1

remove

int remove(const char *filename)


, filename; 0 -1

stdio.h

RemoveDir

bool RemoveDir(const System::AnsiString Dir)


Dir
int rename(const char *oldname,
const char *newname)
oldname,
newname; ; 0 -1
bool RenameFile(const System::AnsiString OldName,
const System::AnsiString NewName)
OldName,
NewName; NewName
OldName,
false
char *searchpath(const char *file)
file , PATH;
NULL
bool SetCurrentDir(const System::AnsiString Dir)
Dir

SysUtils.hpp

rename

RenameFile

searchpath

SetCurrent
Dir
setdisk

setftime

stat

stdio.h

SysUtils.hpp

dir.h

SysUtils.hpp

int setdisk(int drive)


dir.h
drive: 0 ,
1 ..;
int setftime(int handle, struct ftime *ftimep)
io.h
handle
ftimep; 0 -1
int stat(const char *path, struct stat *statbuf)
sys\stat.h
statbuf path; 0 -1

fstat stat stat


. :
st_mode
st_dev

298

st_mode
st rdev
st nlink
st size
st_atime
st mtimc
st_ctime


, st_dev
1

( Windows) ( DOS)
, st_atime
, st_atime

st_ipode
.
:
S_IFCHR
S_IFREG

:
S_IWRITE
S_IREAD

HPFS NTFS st_atime, st_mtime st_ctime:


st_atime
st_mtime
st_ctime

stat:
#include <stdio.h>
#include <time.h>
finclude <sys\stat.h>

s t r u c t stat s t a t b u f ;
FILE *stream;
if ( ( s t r e a m = fopen ("TEST.TXT", "r-t-t") ) == NOLL)
{
ShowMessage(" ");
return;
stat("TEST.TXT", sstatbuf);
fclose(stream);

//

// :
if ( s t a t b u f . s t _ m o d e & S_IFCHR)
Memol->Lines->Add(" ");
if ( s t a t b u f . s t _ m o d e & S_IFREG)
Memol->Lines->Add(" ");
if ( s t a t b u f . s t _ m o d e & S_IREAD)
Memol->Lines->Add(" ")
if ( s t a t b u f .st_mode & S_IWRITE)
Memol->Lines->Add(" " ) ;

. C++, C++Builder, API Windows

299

Memol->Lines->Add(" " +
AnsiString((char)('A1+statbuf.st_dev)));
Memol->Lines->Add(" : " +
IntToStr(statbuf.st^size));
Memol->Lines->Add(" " +
AnsiString ( c t i m e ( S s t a t b u f . s t _ c t i m e ) ) ) ;

remo.ve _unlink . , .
. chmod
_rtl_chmod.
access _waccess , filename. ,
. , , , , .
amode , :
06
04
02
01
00

DOS, OS/2 Windows .


amode 00 04 . DOS
. 06 02 .
filename , , , .
0, .
1, :
ENOENT
EACCES

FileSearch DirList Name.


DirList , . ( , ). , .
searchpath file , PATH. NULL.
FileExists , .
fnmerge path : drive, dir, name ext.
drive:\path\name.ext.
(dir, path, name, ext) NULL. . fnsplit : .
DirectoryExists , Name.
Name , . Name .

300

CreateDir ForceDirectori.es
Dir. ForceDirectories
, , , . ,
ForceDirectories ( " : \ \ T e s t \ \ T e s t l " ) ;

Testl, Test, . , , DirectoryExists.


getcurdir GetCurrentDir
.
API Windows GetSystemDirectory, , Windows. ,
, , . - . , GetWindowsDirectory,
Windows. Windows,
.ini ..
.
, ,
, ,
.
.
IpBuffer GetSystemDirectory GetWindowsDirectory , . "\",
.
uSize . _.
IpBuffer
, . ,
uSize, .
,
. , GetLastError.
. Windows WINDOWS\
SYSTEM :,
Char s[_];
GetSystemDirectory(s,MAX__PATH);

s : C:\WINDOWS\SYSTEM. , , , , .
FileGetAttr, FileSetAttr, _rtl_chmod (. . 3.5.1).

. FileGetAttr _rtl_chmod .
_rtl_chmod
(. . 3.5.1). func = 0
path, func = 1 path attrib.
, ,
SFile, :
rtl chmod(SFile, I, FA HIDDEN);

, C++, C++Builder, API Windows

301

FileGetAttr _rtl_chmod .
,
SFile, :
int a t t r i b = _rtl_chmod(SFile, 0) ;
_rtl_chmod(SFile, 1, a t t r i b I FA_HIDDEN);


Memol SFile:
int a t t r i b = _rtl_chmod(SFile, 0) ;
if (attrib == -1)
{
Memol->Lines->Add(" " + IntToStr(errno));
return;
)
if ( a t t r i b & FA_RDONLY)
Memol->Lines->Add(SFile + " " ) ;
if ( a t t r i b & FA_HIDDEN)
Memol->Lines->Add(SFile + " " ) ;
if ( a t t r i b & FA__SYSTEM)
Memol->Lines->Add(SFile + " " ) ;
if ( a t t r i b & FA_DIREC)
Memol->Lines->Add(SFile + " " ) ;
if ( a t t r i b & FA^ARCH)
Memol->Lines->Add(SFile + " " ) ;

FileAge, FileGetDate FileSetDate


DOS. Time
TSearchRec, FmdFirst FindNext.
TDateTime
FileDateToDateTime. . . 3.3.2, .
getftime , handle ( fileno), ftime, ftimep. setftime : , ftimep. .
EACCES. , . .
0. 1, :
EACCES
EBADF

EINVFNC
ftime :
struct f t i m e
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
);

{
ft_tsec: 5;
ft m i n : 6;
f t _ h o u r : 5;
f t _ d a y : 5;
ft_month: 4;
f t _ y e a r t 7;

//
//
//
//
//
// 1980

"Test.txt",
1 ( , 1)
:

302

FILE *stream;
std::ftime ft;
char buffer[80] ;
if ((stream = fopen ("TEST.TXT", "r+t")) ==NULL)
(
ShowMessage(" ");
return;
}

getftime(fileno(stream), Sft);
//
sprintf(buffer, " : %u/%u/%u",
ft.ft_day, ft.ft_month, f t. f t__year+1980) ;
ShowMessage(buffer);
ft.ft day;
// setftTme(fileno(stream), &ft);
//
fclose(stream);

3.6
3.6.1

_c_exit

_cexit

_exit

abort
Abort
atexit

exit

/
void _c_exit(void)
, exit,
,

void _cexit(void)
, exit,
,
,
void _exit(int status)
,
exit ,
; status
void abort(void)

void Abort(void)
EAbort
int atexit(void (_USERENTRY * func)(void))
func;
0
void exit(int status)
, , , atexit ; status

process.h

process.h

stdlib.h

stdlib.h
SysUtils.hpp
stdlib.h

stdlib.h

, C++, C++Builder, API Windows

303

raise
int raise(int sig)
signal.h
sig; 0
void ( USERENTRY *signal(
signal
signal.h
int sig, void (_USERENTRY *func)
(int sig[, int subcode])))(int)
func sig

atexit . exit _cexit. , ,


.. (. . 1.12.2.). ,
atexit(Exitl);
, :
void E x i t l ( v o i d )

32 .
,
, ..
.
exit . exit. , , , ,
atexit . status exit
.
,
exit, .

exit
exit
_cexit
_c_exit

304

3.6.2

winbase.h
fastcall CreateProcess(
CreateProcess bool
const char * IpAppIicationName,
char * IpCommandLine,
SECURITY ATTRIBUTES * IpProcessAttributes,
_SECURITY_ATTRIBUTES * IpThreadAttributes,
bool blnheritHandles,
unsigned long dwCreationFlags,
void * IpEnvironment,
const char * IpCurrentDirectory,
STARTUPINFO * IpStartupInfo,
PROCESS_INFORMATION * IpProcessInformation)

cwait

process.h
int cwait(int *statloc, int pid, int action);
, statloc , ID -1

excel

int execl(char *path, char *argO, *argl, ..., *argn,


process.h
NULL)
path argO argn

excel e

int execle(char *path, char *argO, *argl


*argn,
process.h
NULL, char **env)
path argO argn env

execlp

int execlp(char *path, char *argO,*argl, ..., *argn,


process.h
NULL)
path argO argn, PATH

int execlpe(char *path, char *argO, *argl, ..., *argn, process.h


NULL, char **env)
path
argO argn, PATH env

execv

int execv(char *path, char *argv[])


process.h
path
argvf]

execve

int execve(char *path, char *argv[], char **env)


path argv[] env

process.h

execvp

int execvp(char *path, char *argv[])


path argv[], PATH

process.h

execvpe

int execvpe(char *path, char *argv[], char **env)


path argv[], PATH env

process.h

, C++, C++Builder, API Windows

305

Find
Executable

HINSTANCE FindExecutable(LPCTSTR IpFile,


ShellLPCTSTR IpDirectory, LPTSTR IpResult) API.h
,

ShellExecute

HINSTANCE ShellExecute(HWND hwnd,


ShellLPCTSTR IpOperation,
API.h
LPCTSTR IpFile,
LPCTSTR IpParameters,
LPCTSTR IpDirectory, INT nShowCmd)

spawnl

int spawnl(int mode, char *path,


char *argO, argl, ..., argn, NULL)
mode
path argO argn

spawnle

int spawnle(int mode, char *path,


process.h,
char *argO, argl, ..., argn,
stdio.h
NULL, char *envp[])
mode path
argO argn envp

spawnlo

int spawnlp(int mode, char *path,


char *argO, argl, ..., argn, NULL)
mode
path argO argn, PATH

spawnlpe

int spawnlpe(int mode, char *path,


process.h,
char *argO, argl, ..., argn,
stdio.h
NULL, char *envp[])
mode
path argO argn, PATH
envp

spawnv

int spawnv(int mode, char *path, char *argvf])


mode
path argv[]

spawnve

process.h,
int spawnve(int mode, char *path, char *argv[],
char *envp[])
stdio.h
mode path
argv[] envp

spawn vp

int spawnvp(int mode, char *path, char *argv[])


mode
path argv[], PATH

process.h,
stdio.h

spawn vpe

int spawnvpe(int mode, char *path, char *argv[],


char *envp[])
mode
path argv[], PATH
envp

process.h,
stdio.h

process.h,
stdio.h

process.h,
stdio.h

process.h,
stdio.h

306

system

wsvstem

wait

WinExec

.
/
stdlib.h
int system(const char *command)
command

stdlib.h
int _wsystem(const wchar_t *command)
command

process.h
int wait(int *statloc)

, statloc , ID
-1
winbase.h
UINT WinExec( LPCSTR IpCmdLine,
UINT uCmdShow)

3.6.3
. 3.6.2 API Windows CreateProcess. FindExecutable. ShellExecute. WinExec
, 32, . ( Windows 95, 98, 2000 NT
):

,
.

ERROR FILE
NOT_FOUND

ERROR PATH
NOT_FOUND
SE_ERR_ACCESSDENIED

6
8

SE_ERR_OOM

10
11

12


, .

ERROR_BAD_FORMAT

.
Windows.
.
Windows, . .
.

, C++, C++Builder, API Windows

307

13


MS-DOS 4.0.

14

15

,
Windows.

16


,
,
.

19


. ,
.

20

DLL, .

21

32- Windows.

26

SE_ERR_SHARE

27

SE ERR
ASSOCINCOMPLETE

, .

28

SE_ERR_DDETIMEOUT

DDE - .

29

SE ERR DDEFAIL

DDE

30

SE_ERR_DDEBUSY

DDE ,
DDE.

31

SE_ERR_NOASSOC

,
, , .

32

SE_ERR_DLLNOTFOUND

DLL.

3.7
3.7.1

_msize

size_t _msize(void *block)


block,
malloc, calloc,
realloc; 32-

malloc.h

new handler typedef void (*pvf)();


pvf _new_handler
, new

new.h

308

alloca

void *alloca(size_t size)


size ;
NULL

malloc.h

AllocMem

SysUtils.hpp
void * AllocMem(Cardinal Size)

Size (void *)
;

calloc

void *calloc(size_t nitems, size_t size)


nitems size ; NULL

free

void free(void *block)


stdlib.h
block,
calloc, malloc, realloc
void GetMemoryManager(TMemoryManager
System.hpp
&MemMgr)
MemMgr
,

GetMemory
Manager

stdlib.h

malloc

void *malloc(size_t size)


size; NULL

stdlib.h
alloc.h

realloc

void *realloc(void *block, size_t size)


block, malloc, calloc, realloc, size;
NULL

stdlib.h

set new
handler

typedef void (new * new_handler)();


new.h
new_handler set_new_handler(
new_handler my_handler)
my_handler,

new

SetMemory
Manager

void SetMemoryManager(
System.hpp
const TMemoryManager &MemMgr)
MemMgr
,

SysFreeMem

extern PACKAGE int SysFreeMem(void * P)


,

System.hpp
ShareMem.hpp

, C++, C++Builder, API Windows

SysGetMem

309

extern PACKAGE void * SysGetMem(int Size) System.hpp


ShareMem.hpp
Size,
;
NULL

SysRealloc
Mem

extern PACKAGE void * SysReallocMem(void * P, System.hpp


int Size) ShareMem.hpp
Size, ; NULL

THeapStatus

System: :THeapStatus GetHeapStatus(void)


System.hpp
heap - ShareMem.hpp
TheapStatus

,
System.hpp ShareMem.hpp, System.hpp ,
, ShareMem.hpp
, , .
heap. : malloc, calloc,
realloc, free new delete (. . 1, . 1.11).
THeapStatus
THeapStatus, :
TotalAddrSpace

,
. .

TotalUncommitted TotalAddrSpace, .
TotalCommitted

TotalAddrSpace,
. TotalUncommitted + TotalCommitted = TotalAddrSpace.

TotalAHocated

.
, .

, OS . TotalAddrSpace.

TotalFree

FreeSmall
FreeBig

,
.
,
.
.

310

Unused
Overhead
HeapErrorCode

,
. : Unused + FreeBig
+ FreeSmall = TotalFree.
, .
.

TotalAddrSpace, TotalUncommitted TotalCommitted , . Total Allocated TotalFree ( heap).


TotalAllocated TotalFree.
SetMemoryManager ,
, . MemMgr TMemoryManage.
TMemoryManage :
,
Size
( malloc). Size GetMem.
. GetMem
, NULL.
, , FreeMem
( free).
FreeMem NULL. FreeMem
, 0. .
ReallocMem , , , Size
( realloc). ,
ReallocMem, NULL, Size
0. ReallocMem
, ,
. , , , .
NULL, .

GetMem

, SetMemoryManager, , , .. GetMemoryManager TMemoryManager, .


.
.
. :
tinclude <malloc.h>
TMemoryManager* mmNew;
TMemoryManager* mmOld;

311

, C++, C++Builder, API Windows


long alloc, dealloc, Nalloc, Ndealloc;
void * _ f a s t c a l l NewGetMem(int Size)
!
alloc += Size;
Nalloc++;
return mm01d->GetMem(Size) ;
int _ fastcall NewFreeMem(void *p)
{
dealloc = _msize (p) ;
Ndealloc ++;
return minOld->FreeMem (p) ;
void * _ fastcall NewReallocMem(void *p, int Size)
(
alloc += Size;
dealloc = _msize (p) ;
Nalloc++;
Ndealloc + +;
return mm01d->ReallocMem(p, Size);
fastcall TForml : :TForml (TComponent* Owner)
: TForm (Owner)
mmNew = new TMemoryManager ();
mmOld = new TMemoryManager ();
mmNew->GetMem = NewGetMem;
mmNew->FreeMem = NewFreeMem;
mmNew->ReallocMem = NewReallocMem;
GetMemoryManager (*mra01d) ;
SetMemoryManager (*mmNew) ;
void
fastcall TForml::ButtonlClick(TObject *Sender)
{
Labell->Caption = "Nalloc = "+IntToStr(Nalloc)+
"Ndealloc = "+IntToStr(Ndealloc)+
" " +IntToStr(alloc)
" " +IntToStr (dealloc);

Buttonl Labell
.

3.7.2

CreateMessage
Dialog

Forms::TForm* CreateMessageDialog(
Dialogs.hpp
const AnsiString Msg,
TMsgDlgType DlgType,
TMsgDlgButtons Buttons)
( )
DlgType, Buttons, -

Msg

312

InnutBox

AnsiString InputBox(constAnsiString ACaption, Dialogs.hpp


const AnsiString APrompt,
const AnsiString ADefault)
ACaption, APrompt
- , ADefault

InputQuerv

bool InputQuery(constAnsiString ACaption,


const AnsiString APrompt,
AnsiString &Value)
ACaption, APrompt
- , ADefault. ,

LoginDialog

DBLogDlg.hpp
bool LoginDialog(
constAnsiString ADatabaseName,
AnsiString &AUserName,
AnsiString &APassword)
Windows (), .
ADatabaseName ,
,
AUserName , , APassword ,

LoginDialogEx bool LoginDialogEx(


DBLogDlg.hpp
const AnsiString ADatabaseName,
AnsiString &AUserName,
AnsiString &APassword,
bool NamcReadOnly)
To , LoginDialog, NameReadOnly,
true,
MessageDlg

int MessageDlg(constAnsiString Msg,


Dialogs.hpp
TMsgDlgType DlgType,
TMsgDlgButtons Buttons, int HelpCtx)
DlgType
Buttons, HelpCtx,
Msg

, C++, C++Builder, API Windows

313

MessageDlgPos int MessageDlgPos(constAnsiString Msg,


Dialogs.hpp
TMsgDlgType DlgType,
TMsgDlgButtons Buttons,
int HelpCtx, int X, int Y)
To , MessageDlg,
(X, Y)
SelectDirectory bool SelectDirectory(const AnsiString Caption, FileCtrl.hpp
const WideString Root,
AnsiString &Directory)
bool SelectDirectory(AnsiString &Directory,
TSelectDirOpts Options,
int HelpCtx)

ShowMessage

void ShowMessage(const System:: AnsiString Msg) Dialogs.hpp


Msg

ShowMessage
Fmt

void ShowMessageFmt(const AnsiString Msg,


Dialogs.hpp
const System: :TVarRec Params,
const int Params_Size)

Msg, Params

ShowMessage
Fmt

void ShowMessagePos(constAnsiString Msg,


Dialogs.hpp
int X, int Y)
Msg
,
X Y

. MessageBox
Application, , ,
.
LoginDialog LoginDialogEx Windows,
. ADatabaseName , , . AUserName -- ,
. LoginDialog
,
User Name. AUserName , , , .
APassword , ,
.
LoginDialog true, ,
.

, ,
. , false.
, LoginDialog, , User Name. Login-

314

DialogEx . true NameReadOnly.


LoginDialog LoginDialogEx
.
. , , , .

3.7.3

extern PACKAGE void Beep(void)


SysUtils.hpp
C++Builder,
BOOL Beep(DWORD dwFreq, DWORD dwDuration);

API Windows, Windows NT/


2000/XP, dwFreq dwDuration

MessageBeep BOOL MessageBeep(UINT uType);


API Windows,
uType
BOOL PlaySound(LPCSTR pszSound,
PlaySound
mmsystem.hpp
HMODULE hmod,
DWORD fdwSound)
API Windows, ,
,

C++Builder Beep , MessageBeep API Windows . , Windows, (


).
,
.
, ..
.
API Windows, Windows NT/2000/XP, . Windows NT dwFreq . 37 32,767 ( 0x25 Ox7FFF).
dwDuration .
: .
Windows NT/2000/XP. Windows 95 98 C-b+Builder.
, C++Builder , API Windows
. . GetLastError.

, C++, C++Builder, API Windows

315

, , .
MessageBeep . , ,
[sounds] .
MessageBeep . :

OxFFFFFFFF

MB_ICONASTERISK

MB_ICONEXCLAMATION

MBJCONHAND

MB_ICONQUESTION

MB_OK

(true).
,
GetLastError.
MessageBeep .
MessageBeep , .
, .
PlaySound API Windows
, , .
pszSound
. fdwSound
(SND_FILENAME, SND_ALIAS SND^RESOURCE) pszSound , . ,
Windows WIN.INI . , . , pszSound
.
, pszSound, . PlaySound : , Windows, Windows, , PATH, , .
OpenFile.
, PlaySound . , , false.
pszSound 0, . ,
, SND_PURGE fdwSound.
hmod fdwSound
SND_RESOURCE. hmod -

316

, , . hmod 0.
fdwSound . "|".
:
pszSound
Windows WIN.INI.
SND FILENAME
SND RESOURCE.
szSound SND_ALIAS_ID
.
SND_APPLICATION .
PlaySoSND_ASYNC
und .
, PlaySound
pszSound, 0.
pszSound .
SND FILENAME
,
SND_LOOP
PlaySound pszSound, 0.
SND_ASYNC .
.
SND_MEMORY
pszSound
.
, . SND_NODEFAULT
, PlaySound , .
, SND_NOSTOP
, , , PlaySound false,
. , PlaySound , .
, SND_NOWAIT
.
, SND_PURGE
. pszSound 0, .
pszSound '0, , . SND_RESOURCE.
pszSound .
SND_RESOUECE
hmod .
SND_SYNC
.
PlaySound .

SND_ALIAS

317

, C++, C++Builder, API Windows

PlaySound true,
false.

3.7.4 C++ C++Builder

ARRAYSIZE

ARRAYSIZE(const void *a)


sysdefs.h

bsearch

void *bsearch(const void *key,


stdlib.h
const void *base, size_t nelem,
size_t width, int (_USERENTRY *fcmp)
(const void *, const void *))
key () base nelem width
fcmp;

EXISTING
ARRAY

EXISTINGARRAY(const void *a)



sysdefs.h

getenv

char *getenv(const char *name)



name

stdlib.h

GetLongllint extern PACKAGE System::AnsiString GetLongHint( Controls.hpp


const System::AnsiString Hint)
, Hint
GetShort
Hint

extern PACKAGE System::AnsiString GetShortHint( Controls.hpp


const System::AnsiString Hint)
, Hint

Ifind

void *lfind(const void *key,


stdlib.h
const void *base, size_t *num,
size_t width, int (_USERENTRY *fcmp)
(const void *, const void *))
key () base num width
fcmp;

stdlib.h
void *lsearch(const void *key,
void *base, size_t *num,
size_t width, int(_USERENTRY *fcmp)
(const void *, const void *))
key () base num width
fcmp;
, ;

Isearch

318

OPENARRAY OPENARRAY(type argl, ..., type arg!9)


, 19
ParamCount extern PACKAGE int fastcall ParamCount(void);

extern PACKAGE AnsiString fastcall
ParamStr
ParamStr(int Index);
Index

int putenv(const char *name)


putenv
name
void qsort(void *base, size t nelem, size t width,
qsort
int (_USERENTRY *fcmp)
(const void *, const void *))
*
() base nelem width
fcmp
extern PACKAGE TShortCut ShortCut(Word Key,
Shortcut
Classes-TShiftState Shift)
, Key Shift

extern PACKAGE System::AnsiString


Shortcut
ShortCutToText(TShortCut Shortcut)
ToText
Shortcut, ,
void swab(char *from, char *to, int nbytes)
swab
nbytes from to,

extern PACKAGE TShortCut TextToShortCut(
TextTo
System::AnsiString Text)
Shortcut
Text ,

type va_arg(va_list , type)
type
;
va_start
va_arg
va end
void va_end(va_list )
, va_start va_arg

sysdefs.h

System.hpp
System.hpp

stdlib.h
stdlib.h

Menus.hpp

Menus.hpp

stdlib.h

Menus.hpp

stdarg.h

stdarg.h

, C++, C++Builder, API Windows

va start

319

void va start(va list ap, lastfix)


stdarg.h
,
, ; lastfix

EXISTINGARRAY, ARRAYSIZE, OPENARRAY


. .
. 2.11.3.
Format . 4.
bsearch, Ifind, Isearch, qsort (). base , nelem num ,
width , , fcmp , , .
bsearch () , key. , ,
.
fcmp :
*eleml *elem2. ,
, :

<0
== 0
>0

*eleml < *elem2


*eleml == *elem2
*eleml > *elem2

< , *eleml *elem2, > , *eleml


*elem2, , . , , , , .
qsort , . ,
.
qsort bsearch.
array . fcmp , qsort bsearch. Buttonl
qsort,
bsearch , Editl.
#include <malloc.h>
tinclude < s t d l i b . h >
int a r r a y [ ] = ( 8 0 0 , 1 2 3 , 5 1 2 , 6 2 7 , 9 3 3 , 1 4 5 ) ;
int fcmp (const void *pl, const void *p2)
{ return (*(int*)pl - *(int*)p2); }
void

fastcall TForml::ButtonlClick(TObject *Sender)

320

int key = StrToInt (Editl->Text) ;


int *elem;
qsort (array, ARRAYSIZE ( a r r a y ) , sizeof ( i n t ) , f c m p ) ;
elem = (int *) bsearch ( & k e y , a r r a y , ARRAYSIZE ( a r r a y ) ,
sizeof ( i n t ) , fcmp) ;
if (elem == 0) ShowMessage ( " " + IntToStr ( k e y ) +
" ") ;
else ShowMessage (" " + IntToStr (*elem) +
" " + IntToStr (elem- a r r a y ) ) ;
}

Ifind Isearch . , , . , Isearch, , . Ifind Isearch


. , .
Isearch, . array .
fcmpl . Buttonl , ' Editl.
, .
tinclude <malloc.h>
#include <stdlib.h>
int array[10] = {800,123,512,627,933,145};
unsigned Narray = 6;
int fcmpl (const void *pl, const void *p2)
{ return (* (int*) pi != * (int*) p2) ; }
void _ fastcall TForml : :ButtonlClick (TObj ect *Sender)
{
int key = StrToInt (Editl->Text) ;
int *elem;
elem = (int *) Isearch (Skey, array, SNarray,
sizeof (int), fcmpl);
ShowMessage (" " + IntToStr (key) +
" " + IntToStr (elem- array) ) ;
}

GetShortHint GetLongHint

< > | < >

, , Hint.
getenv putenv .
name=string\0. getenv
name. getenv ,
, . ,

Labell->Caption = getenv ("PATH") ;

Labell PATH.
DOS OS/2 . , .

, C++, C++Builder, API Windows

321

,
NULL. getenv name "name=", name . ,
getenv("PATH=");

PATH.
putenv . name " name=string". :
putenv("=:\\temp");

Shortcut, ShortCutToText TextToShortCut Shortcut ,


. Shortcut Key, , Shift,
Shift, Ctrl Alt,
TShortCut, Word. TextToShortCut . Shortcut ,
TextToShortCut ,
.
ShortCutToText
Shortcut TShortCut. , .
.
MOpen->ShortCut = Shortcut('', TShiftState() ssCtrl);

Ctrl-O.
MOpen->ShortCut = S h o r t c u t ( ' 1 , T S h i f t S t a t e ( ) < < s s C t r l s s A l t ) ;

Ctrl-Alt-O.
. , Open. ShortCutToText , . TextToShortCut
. , , Ctrl-O
" ", "Ctrl+0".
void
f a s t c a l l T F o r m l : : B u t t o n l C l i c k ( T O b j e c t *Sender)
{
Editl->Text = ShortCutToText (MOpen->ShortCut);
}
//

void
f a s t c a l l T F o r m l : : B u t t o n 2 C l i c k ( T O b j e c t *Sender)
{
MOpen->ShortCut = TextToShortCut(Editl->Text);
}

ParamStr ParamCount .
ParamStr Index.
. ,
ParamStr(O) , , "D:\\TEST\\PROJECT1.EXE", ..
, .
. , - , ,
.
- , -

322

ParamStr(l), ParamStr(2) .. ,
. .
ParamCount , .
. ,
for

(int i=l;i<=ParamCount ( ) ;i
if (LowerCase (ParamStr ( i ) ) == "-e")

( ),
" " " ".
, CmdLine (char *).
,
. CmdLine,
, , . . 1, . 1.2.2.

3.7.5 API Windows

CloseWindow

BOOL Close Window(HWND hWnd)


, , ,
hWnd

Destroy Window

BOOL DestroyWindow(HWND hWnd)


, hWnd,
,

Enable Window

BOOL Enable Window(HWND hWnd, BOOL bEnable)


( bEnable = true)
( bEnable = false) , hWnd

FindWindow

HWND FindWindow(LPCTSTR IpClassName,


LPCTSTR IpWindowName)
IpClassName IpWindowName

GetLastError

DWORD GetLastError(VOID)

GetNextWindow HWND GetNextWindow(HWND hWnd, UINT wCmd)


hWnd Z-
GetWindow

HWND GetWindow(HWND hWnd, UINT wCmd)


, hWnd wCmd

GetWindowText int GetWindowText(HWND hWnd, LPTSTR IpString,


int nMaxCount)
,
hWnd, IpString nMaxCount

323

, C++, C++Builder, API Windows

3.8 Windows
Windows . 1, . 1.14. , . 1.

PostMessage

BOOL PostMessage(HWND hWnd, UINT Msg,


winuser.h
WPARAM wParam, LPARAM IParam)
, ,

winuser.h
RegisterWindow UINT RegisterWindowMessage(
LPCTSTR IpString)
Message
,
SendMessage PostMessage
SendMessage

LRESULT SendMessage(HWND hWnd,


winuser.h
UINT Msg, WPARAM wParam,
LPARAM IParam)

,


. 3 , C++, C++Builder API
Windows. ( 300),
.
. ,
,
, C++, ++ilder API Windows. ,
[2].
. ,
TDateTime. ,
. , .

abort

tinclude < s t d l i b . h >


void abort(void);

abort , .
3.
abort , , raise(SIGABRT), SIGABRT (. . signal raise
, . 1, . 1.13.
, abort stderr (. . 2.10.2.4)
Abnormal program termination
exit 3.

Abort
EAbort
SysUtils.hpp

extern PACKAGE void

f a s t c a l l Abort ( v o i d ) ;

Abort
(, ) .
EAbort,
, .
Abort ,
try ...
finally.
, . ,
-

326

, try ... catch :


catch(EAbortS)

abs

math.h, stdlib.h

tinclude <stdlib.h>
int abs (int x ) ;
long labs(long int x) ;
tinclude <math.h>
double fabs(double x);
long double fabsl(long double x);

.
fabs fabsl . abs labs . abs
, stdlib.h, . abs,

#include <stdlib.h>

#undef

abs

abs 0 INT_MAX (
limit.h).

AnsiCompareStr

SysUtils.hpp

extern PACKAGE int


fastcall
AnsiCompareStr(const AnsiString SI, const AnsiString 5 2 ) ;
extern PACKAGE int
fastcall
AnsiCompareText(const A n s i S t r i n g SI, const A n s i S t r i n g S 2 ) ;

SI S2 AnsiString. < 0, SI < S2, 0, SI = S2, > 0, SI > S2.


, . , , ,
, . . , ,
, ( ) .
, ,
, .

327

AnsiCompareText , , . .. "" "" . , CompareText. .


AnsiCompareStr , .
(, ) ( ). ""
"".

( ) Editl Edit2.
if (AnsiCompareStr (Editl->Text, Edit2->Text) < 0)
else if (AnsiCompareStr (Editl->Text, Edit2->Text) == 0)
else . . .

AnsiCompareText.
S1 S2
Editl->Text

Edit2->Text

AnsiCompareStr

AnsiCompareText

<0

<0

>0

Edit

edit

>0

<0

<0

AnsiCompareText
.
. . AnsiCompareStr .

AnsiLowerCase

.
SysUtils.hpp, string.h, mbstring.h

extern PACKAGE AnsiString

fastcall
AnsiLowerCase (const AnsiString S) ;
extern PACKAGE char *
fastcall
AnsiStrLower (char * Str);
extern PACKAGE AnsiString
fastcall
Lowercase(const AnsiString S);
extern PACKAGE char *
fastcall StrLower (char * Str);
char *strlwr(char *s);
wchar t * wcslwr(wchar_t *s);
unsigned char *_mbslwr(unsigned char *s) ;

Str s (char *) S
AnsiString, . StrLower, LowerCase, strlwr, _wcslwr, _mbslwr -

328

.
AnsiStrLower AnsiLowerCase. AnsiLowerCase
.
VCL AnsiLowerCase LowerCase, AnsiString.

Editl : "Hi! !". , , .

AnsiLowerCase(Edit I ->Text)

LowerCase(Editl->Text)

hi! !
hi! !

AnsiStrLower((Editl->Text).c_str())

hi! !

StrLower((Editl->Text).c_str())

hi! !

, AnsiLowerCase, AnsiStrLower , LowerCase, Sir Lower .


' VCL AnsiLowerCase, LowerCase , .
. . AnsiPos .
AnsiPos
.
SysUtils.hpp

extern PACKAGE int


fastcall
AnsiPos(const AnsiString Substr, const AnsiString S);
extern PACKAGE char *
fastcall
AnsiStrPos (char * Str, char * SubStr) ;
extern PACKAGE char *
fastcall
StrPos(const char * Strl, const char * Str2);

AnsiStrPos StrPos SubStr (STR2) Str (STR1).


. SubStr Str, NULL.
,
AnsiStrPos, StrPos. AnsiStrPos.
AnsiPos ,
, 1. ,
S Substr, 1. , 0.
, : AnsiStrPos StrPos , AnsiPos
.

- , , , Edit2, , Editl. , .

329

AnsiPos. , ,
, AnsiLowerCase :
if

(AnsiPos(AnsiLowerCase(Edit2->Text),
A n s i L o w e r C a s e ( E d i t l - > T e x t ) ) > 0)

AnsiUpperCase :
if

(AnsiPos(AnsiUpperCase(Edit2->Text),

AnsiUpperCase(Editl->Text)) > 0)

AnsiPos AnsiStrPos StrPos:


if

(AnsiStrPos(AnsiLowerCase(Editl-XText).c_str(),
A n s i L o w e r C a s e ( E d i t 2 - > T e x t ) . c _ s t r ( ) ) != NULL)

. ,
AnsiStrPos StrPos, AnsiPos, , .
Labell Editl, Edit2:
Labell->Caption =
AnsiStrPos(AnsistrLower((Editl->Text).c_str()),
AnsiStrLower((Edit2->Text).c_str()));

, .
AnsiStrLower AnsiStrUp AnsiLowerCase. LowerCase. StrLower. AnsiUpperCase. UpperCase. StrUpper. ,
.

AnsiStrComp
.
SysUtils.hpp

extern PACKAGE int

f a s t c a l l A n s i S t r C o m p ( c h a r * SI,

char * 3 2 ) ;

SI S2 . < 0, SI < S2, 0, SI = S2, > 0, SI > S2.


, . , , , , . (, ) ( ). . ,
, ,
( ) .
, , ,
.
, , StrComp .

330

AnsiStrlComp
.
SysUtils.hpp

extern PACKAGE int

f a s t c a l l A n s i S t r l C o m p ( c h a r * SI, char * S 2 ) ;

SI S2 . < 0, SI < S2, 0, SI = S2, > 0, SI > S2.


, .
StrlComp, .
, . ,
, .
, , , ,
. . ,
, ,
( ) .
, ,
, .
. AnsiCompareText. AnsiStrlComp.

( ) Editl Edit2.
String
String
switch
{
case

SI = Editl->Text;
S2 = Edit2->Text;
(AnsiStrlComp(SI.c_str(),

S2.c_str()))

-1: . . . ;
break;
case 0 : . . . ;
break;
case 1 :

, S1 S2 switch :
switch

(AnsiStrlComp((Editl->Text).c_str(),

(Edit2->Text).c_str()})

S1 S2
S1

S2

" 1"

" 2"

-1

"

""

+1

" 1"

" 1"

""

""

-1

331

AnsiStrLower
.
. . AnsiLowerCase .

AnsiStrPos

.
. . AnsiPos .

AnsiStrUpper
.
. . AnsiUpperCase .

AnsiToOem DOS
, 16- MS-DOS. , CharToOem.
(. . CharToOem
DOS).

AnsiUpperCase

.
SysUtils.hpp, string.h, mbstring.h.

e x t e r n PACKAGE char *
fastcall AnsiStrUpper(char * Str);
e x t e r n PACKAGE A n s i S t r i n g
fastcall
AnsiUpperCase(const AnsiString S);
extern PACKAGE char *
fastcall StrUpper(char * Str);
extern PACKAGE A n s i S t r i n g
fastcall
Uppercase(const AnsiString S ) ;
char * s t r u p r ( c h a r * s ) ;
wchar_t *_wcsupr(wchar_t * s ) ;

unsigned char *_mbsupr(unsigned char *s) ;

Str s (char *), S


AnsiString, . StrUpper, UpperCase, strupr, _wcsupr, _mbsupr .
AnsiStrUpper AnsiUpperCase. AnsiUpperCase
.
VCL
AnsiUpperCase Uppercase, AnsiString.

Editl : "Hi! !". , , .

3(32

AnsiUpperCase(Editl->Text)
UpperCase(Editl->Text)
AnsiStrUpper((Editl->Text).c_str())

HI! !

StrUpper((Editl->Text).c_str()>

HI! !

HI! !
HI! !

, AnsiUpperCase, AnsiStrUpper , UpperCase, StrUpper .


, VCL AnsiUpperCase, UpperCase , .
. . AnsiPos .
assert
.

#include <assert.h>
void a s s e r t ( i n t test);

assert . test ( ), assert


stderr :
Assertion f a i l e d : test, f i l e < >, line < >

assert abort.

tinclude <assert.h>

#define NDEBUG

assert . , - , ,
.
, , , -
NULL.
:
a s s e r t ( == N U L L ) ;

NULL,
, , .
Bounds
TRect.
Types.hpp, Classes.hpp.

#include <Types.hpp>
struct TRect
{
int l e f t , top, right, bottom;

333

struct TPoint
(
int x;
int y;
);
extern PACKAGE Types::TRect
fastcall
Bounds(int ALeft, int ATop, int AWidth, int AHeight);
tinclude <Classes.hpp>
extern PACKAGE TRect
fastcall
Rect(int ALeft, int ATop, int ARight, int ABottom);
. extern PACKAGE TRect
fastcall
Rect (const TPoint ATopLeft, const TPoint ABottomRight) ;

TRect. C++Builder Windows.


.
. .
Bounds TRect X (ALeft) Y (ATop)
, (AWidth) (AHeight).
Rect X (ARight) Y (ATop)
. Rect
TPoint, . TPoint Point.
C++Builder , , , BoundsRect, ClientRect .

Memol
Panel 1, , 10 ( ), 40 (, ):
Memol->BoundsRect = R e c t ( 1 0 , 4 0 , P a n e l l - > C l i e n t W i d t h - 1 0 ,
Panell->ClientHeight-10);

To :
Memol->BoundsRect = B o u n d s ( 1 0 , 4 0 , P a n e l l - > C l i e n t W i d t h - 2 0 ,
Panell->ClientHeight-50);

, Rect Point.
TRect TPoint:
TRect R, R l , R3;
R = Rect(10,100,20,200);

Rl = R;

TPoint PI, P2;


PI = Point(10, 100) ;
P2 = Point (10, 200);
R3 = TRect(PI, P2);'
TRect R2(PI, P2);
R.Left'= 15;
int W = R.Width (); <
if(Rl != R) ...

334

calloc
.
. . malloc . .
ceil
.
. . Ceil .
Ceil
.
math.fi math.hpp.

#include <math.h>
double ceil(double x) ;
double floor(double x);
long double ceill (long double x);
long double floorl(long double x);
ttinclude <math.hpp>
extern PACKAGE int
extern PACKAGE int

fastcall Ceil(Extended X);


fastcall Floor(Extended X);

ceil, ceill, Ceil, floor, floorl, Floor , .


: ceil, ceill Ceil ( , , ); floor, floorl Floor
( , , ).
, ,
, .
:

X = 3.5
ceil, ceill, Ceil
4
floor, floorl, Floor 3

X = -3.5

X=3

-3

-4

ceill
.
. . Ceil .
cgets
.
. . fputs / .

335

CharToOem, CharToOemBuff DOS


API Windows, MS-DOS.
winuser.h.

#include <systera.hpp>
BOOL CharToOem(
LPCTSTR IpszSrc,
LPSTR -IpszDst
);
BOOL CharToOemBuff(
LPCTSTR IpszSrc,
LPSTR IpszDst,
DWORD cchDstLength
);

//
//
//
//
//

ASCII (
) MS-DOS. , , . ,
DOS.
IpszSrc , . IpszDst ,
. cchDstLength CharToOemBuff , .
, .
, ANSI Unix. , ANSI, , .. IpszSrc IpszDst .
.
OemToChar. .

,
DOS.
CharToOem.
tinclude <stdio.h>
#include <system.hpp>
int main()
{
char SI[20], S2[20];
CharToOem(" :\", SI);
printf(SI);
scanf ("%20s", S2);
CharToOem(", ", SI);
printf(strcat(strcat(SI, 32) , "! ! !\n"));
// DOS
fflush(stdin) ;
getchar () ;
return 0;
}

, RichEditl DOS
, .

336
#include <stdio.h>
if (SaveDialogl->Execute() )
{
char *S = (char *) malloc(sizeof(RichEditl->Text)+1);
CharToOem((RichEditl->Text) .c_str(), S) ;
FILE *F;
F = fopen((SaveDialogl->FileName).c_str(), "wt");
fprintf(F,"%s", S);
fclose (F);
free (S) ;
}

if .
, S, RichEditl.
.
, .
.

_clear87 FPU
FPU.
float.h.

tinclude < f l o a t . h >


unsigned int _clear87
unsigned int _ c l e a r f p

(void);
(void);

_clear87 _clearfp FPU (. . 1.9.3),


.
:

IE

DE

ZE

UE

SF

ES

0 (CF)

2 (PF)

10

ST

11-13

3 (ZF)

14

BF

FPU

15

337

. ,
, ZE
1, .
_!87 _clearfp.
. _clearfp Microsoft.
, .

.
,
controls?. , :
_contro!87(Ox3F, O x 3 F ) ;


, . ,
if ( c l e a r 8 7 ( ) & 0 x 4 ) ShowMessage(" " ) ;


.
if (_clear87() & 0x30)
ShowMessage(" " ) ;

_clearfp FPU
FPU.
. . _clear87 FPU.

CompareDate
.
Datelltils.hpp.

tinclude <DateUtils.hpp>
typedef int TValueRelationship;
extern PACKAGE Types::TValueRelationship
fastcall
CompareDate(const System::TDateTime A,
const System::TDateTime B) ;
extern PACKAGE Types::TValueRelationship
fastcall
CompareDateTime(const System::TDateTime A,
const System::TDateTime B) ;
extern PACKAGE Types::TValueRelationship
fastcall
CompareTime(const System::TDateTime A,
const System::TDateTime B);

CompareDate, CompareDateTime, CompareTime TDateTime. -. CompareDate , . ,


, , .
CompareDateTime , .
, , -

338

. CompareTime , .
, , . , , , > ,
, .
:

LessThanValue
EqualsValue
GreaterThan Value

-1
0

+1

A <B
A=
A>

CompareDateTime
.
. . CompareDate .
CompareText
.
SysUtils.hpp.

extern PACKAGE int

f a s t c a l l C o m p a r e T e x t ( c o n s t A n s i S t r i n g SI,
const A n s i S t r i n g S 2 ) ;

SI S2 AnsiString. . .
> 0, SI = S2. 0.
,
CompareText(Editl->Text, Edit2->Text)

0, Editl Edit2
. , "Edit" "edit".
.
(, "" ""),
, .. .
AnsiStrComp.
CompareTime
.
. . CompareDate .
Compare Value
.
Math.hpp.

typedef

int

TValueRelationship;

extern PACKAGE T V a l u e R e l a t i o n s h i p
fastcall
CompareValue(const int A, const i n t ' B ) ;
extern PACKAGE T V a l u e R e l a t i o n s h i p
fastcall
CompareValue(const
int64 A, const
int64 B ) ;

339

extern PACKAGE TValueRelationship


fastcall
CompareValue(const float A, const float B,
float Epsilon = 0);
extern PACKAGE TValueRelationship
fastcall
CompareValue(const double A, const double B,
double Epsilon = 0);
extern PACKAGE TValueRelationship
fastcall
CompareValue(const Extended A, const Extended B,
Extended Epsilon =0);
extern PACKAGE bool
extern PACKAGE bool
extern PACKAGE bool

fastcall SameValue(const float A,


const float B, float Epsilon = 0);
fastcall SameValue(const double A,
const double B, double Epsilon = 0);
fastcall SameValue(const Extended A,
const Extended B, Extended Epsilon = 0);

CompareValue . :

-1

LessThanValue

<

EqualsValue

+1

GreaterThanValue

>

Epsilon
, . .
SameValue
Epsilon. true,
Epsilon. ,
Epsilon = 0, . ,
. Epsilon.

, = 10.05, = 10. CompareValue(A, ) +1, CompareValue(A, B, 0.01*abs(B))


0, 1%.
SameValue(A, ) false, SameValue(A, B, 0.01*abs(B))
true.

_contro!87 FPU
FPU.
float.h, System.hpp.

#include < f l o a t . h >


unsigned int _contro!87(unsigned int newcw,
unsigned int _ c o n t r o l f p ( u n s i g n e d ' int n e w c w ,

unsigned int m a s k ) ;
unsigned int m a s k ) ;

#include <System.hpp>
extern PACKAGE Word ^ f a s t c a l l Get8087CW (void) ;
extern PACKAGE void
fastcall Set8087CW(Word NewCW);

340

FPU (. . 1.9.3),
, .
,
- . , ,
. , OpenGL .
_contro!87 _controlfp newcw FPU. mask , , newcw . , mask
1. ,
_contro!87(0x4, 0 x 4 )

, 0100. , ( ) , .
_contro!87 ( 0 x 4 , Ox3F)

( 00111111, 00000100) 3-
0 6- , . .
.
, . ,
u n s i g n e d int m = _ c o n t r o ! 8 7 ( 0 , 0 ) ;

m ,
.
_controlfp Microsoft.
_controI87 , DM, .
Get8087CW .
Set8087CW NewCW.
_controlfp, _contro!87, Set8087CW
DefauIt8087CW. FPU.
. GetExceptionMask. SetExceptionMask. GetPrecisionMode. SetPrecisionMode. GetRoundMode. SetRoundMode.

-
, , :
//
unsigned int m = _ c o n t r o ! 8 7 ( 0 , 0 ) ;
_ c o n t r o ! 8 7 ( 0 x 4 , 0 x 4 ) ; //
<, >
controls?(m,

OxFFFF);

//

341

m
_contro!87 . . .
, Get8087CW
Set8087CW:
Word 01d8087CW;
01d8087CW = G e t 8 0 8 7 C W ( ) ; //
Set8087CW(Oxl33f);
//
<, >
Set8087CW(01d8087CW);

//

.
, . 1
ZM (. . 1.9.3), . ,
- ,
. 1 ( ), IM,
. .
:
Set8087CW(Get8087CW()

| OxD);

, Get8087CW. ZM
1, .

Set8087CW(Get8087CW | 5 ) ;

1 ZM IM.
. 1.9.3, . 1 , FPU.

_controlfp FPU
FPU.
. . _contro!87 FPU.

cprintf
.
. . fprintf .

cputs
.
. . fputs / .

CreateMessageDialog
, .
. . MessageDlg .

CreateProcess
API Windows, .

342

bool

fastcall CreateProcess(
const char * IpApplicationName,
char * IpCommandLine,
_SECURITY_ATTRIBUTES * IpProcessAttributes,
_SECURITY_ATTRIBUTES * IpThreadAttribUtes,
bool blnheritHandles,
unsigned long dwCreationFlags,
void * IpEnvironment,
const char * IpCurrentDirectory,
STARTUPINFO * IpStartupInfo,
PROCESS__INFORMATION * IpProcessInforraation

);

CreateProcess (). IpApplicationName IpCommandLine. , IpApplicationName NULL,


, IpCommandLine. : 32- Windows, MS-DOS, OS/2 ..
Windows MS-DOS, IpApplicationName
NULL, IpCommandLine.
, , , IpApplicationName = NULL IpCommandLine.
,
.. ,
. .
, :
,

Windows, GetSystemDirectory
SYSTEM (Windows NT/2000/XP).
Windows, GetWindowsDirectory
, PATH
, (true).
0 (false).
, GetLastError.
CreateProcess WinExec LoadModule, CreateProcess.
CreateProcess ,
. . ,
. WaitForInputldle.
. , , - , . WaitForSingleObiect.
,
() CloseHandle.

343

, .
ExitProcess.

.
.
IpApplicationName

IpCommandLine

IpProcess Attributes ,
IpThreadAttributes
blnheritHandles
dwCreationFlags
IpEnvironment

,
: , (
).
IpApplicationName = NULL, IpCommandLine ( . ).
,
. IpCommandLine = NULL,
IpApplicationName ( . ).
PSequrityAttributes,

. NULL, .
,
. true
, .
dwCreationFlags, .
. NULL, . :
<>=< >

,

. UNICODE
ANSI (. dwCreationFlags). ANSI (
, ). UNICODE .
,
IpCurrentDirectory
. , .
NULL, .
STARTUPINFO IpStartupInfo
TStartupInfo,
.
IpProcessInformation PROCESS_INFORMATION
TProcessInformation,

.

344

IpProcessAttributes, IpThreadAttributes, IpEnvironment, blnheritHandles


. ,
NULL, false. IpCurrentDirectory , . -, .
NULL, .
dwCreationFlags , .
, ,
( ) (|).
CREATE_DEFAULT
ERROR MODE

.
SetErrorMode. .

CREATE NEW CONSOLE

.

DETACHED PROCESS.

CREATE_NEW_PROCESS
GROUP "


: ,
.
,
IpProcessInf filiation. GenerateConsoleCtrlEvent
Ctrl-C Ctrl-Break .

CREATE_SEPARATE
WOW VDM

Windows NT
16- .
VDM.
.

CREATE_SHARED
WOW VDM

Windows NT
16- . DefaultSeparateVDM Windows WIN.INI
true,
VDM.

CREATE SUSPENDED

() ,
ResumeThread.

CREATE_UNICODE
ENVIRONMENT

,
IpEnvironment,
Unicode. ANSI.

DEBUG PROCESS


.

.
WaitForDebugEvent
, CreateProcess.

345

DEBUG ONLY THIS


PROCESS

, , .

DETACHED_PROCESS


. AllocConsole
. CREATE_NEW_CONSOLE.

dwCreationFlags . ,
NORMAL_PRIORITY_CLASS, IDLE_PRIORITY_CLASS. IDLE_PRIORITY_CLASS.
:
HIGH_PRIORITY_CLASS

, .

IDLE_PRIORITY_CLAS S

. .
.

NORMAL PRIORITY
CLASS

REALTIME PRIORITY
CLASS

,
,
.

IpStartupInfo TStartupInfo, STARTUPINFO API Windows.


. (GUI) , CreateWindow ShowWindow. .
:
typedef STARTUPINFOA STARTUPINFO;
typedef LPSTARTUPINFOA LPSTARTUPINFO;
typedef struct ^STARTUPINFOA {
DWORD
cb;
LPSTR
IpReserved;
LPSTR
IpDesktop;
LPSTR
IpTitle;
DWORD
dwX;
DWORD
dwY;
DWORD
dwXSize;
DWORD
dwYSize;
DWORD
dwXCountChars;
DWORD
dwYCountChars;
DWORD
dwFillAttribute;
DWORD
dwFlags;
WORD
wShowWindow;
WORD
cbReserved2;
LPBYTE lpReserved2;
'HANDLE hStdlnput;

346
HANDLE hStdOutput;
HANDLE hStdError;
} STARTUPINFOA, *LPSTARTUPINFOA;

:
Cb

IpReserved

. NULL.

IpDesktop

Windows NT.
desktop, desktop
.

IpTitle

.
GUI , , NULL.

dwX, dwY

, dwFlags
STARTF_USEPOSITION.
STARTF_USEPOSITION
.

dwXSize,
dwYSize

, dwFlags
STARTF_USESIZE.
STARTF_USESIZE .

dwXCountChars, , dwFlags
dwYCountChars STARTF_USECOUNTCHARS.
STARTF_USECOUNTCHARS , , .
.
dwFillAttribute

, dwFlags
STARTF_USEFILLATTRIBUTE.
STARTF_USEFILLATTRIBUTE
, , . : FOREGROUND_BLUE,
FOREGROUND_GREEN, FOREGROUND_RED,
FOREGROUND_INTENSITY, BACKGROUND_BLUE,
BACKGROUND_GREEN, BACKGROUND_RED,
BACKGROUND_INTENSITY. , :
FOREGROUND_RED BACKGROUND_RED |
BACKGROUND GREEN BACKGROUND BLUE.

dwFlags

wShowWindow

cbReserved2
lpReserved2
hStdlnput
hStdOutput
hStdError

347

, ,
.
:
STARTF_USESHOWWINDOW
wShow Window
STARTF_USEPOSITION dwX dwY
STARTF_USESIZE dwXSize dwYSize
STARTF_USECOUNTCHARS dwXCountChars dwYCoimtChars
STARTF_USEFILLATTRIBUTE dwFillAttribute
STARTF_FORCEONFEEDBACK ,
2 CreateProcess. GUI, 5
. ,
5 . GetMessage
STARTF_FORCEOFFFEEDBACK

STARTF_USESTDHANDLES
, ,
hStdlnput, hStdOutput, hStdError
, dwFlags
STARTF_USESHOWWINDOW.
SW , WINUSER.H. , SW_SHOWNORMAL , SWJHIDE .
, 0.
, NULL.
, dwFlags
STARTF_USESTDHANDLES. .
, dwFlags
STARTF_USESTDHANDLES. .
, dwFlags
STARTF_USESTDHANDLES. .


cb . , .
IpProcessInformation TProcessInformation,
PROCESS_INFORMATION API Windows.
.

348

4
:
typedef struct __PROCESS_INFORMATION {
HANDLE hProcess;
HANDLE hThread;
DWORD dwProcessId;
DWORD dwThreadld;
} PROCESS_INFORMATION, *PPROCESS_INFORMATION,
*LPPROCESS_INFORMATION;

:
.
, .
() hThread
. , .
dwProcessId . .
dwThreadld . .

hProcess

CreateProcess
, :
STARTUPINFO Startlnfo = { sizeof (TStartupInfo) };
PROCESS_INFORMATION Proclnfo;
LPCTSTR s;
Startlnfo.cb = sizeof (Startlnfo);
Startlnfo.dwFlags = STARTF_USESHOWWINDOW;
Startlnfo.wShowWindow = SW_SHOWNORMAL;
if (! CreateProcess(NULL, "arj a all *.*",
NULL, NULL, false,
CREATE^NEW^CONSOLE |
HIGH__PRIORITY_CLASS,
NULL, NULL, SStartlnfo, SProcInfo))
ShowMessage(" " + IntToStr(GetLastError()));
else
{
if (WaitForSingleObject(Proclnfo.hProcess, 10000)
== WAIT^TIMEOUT)
ShowMessage(" 10 . ");
CloseHandle(Proclnfo.hProcess);

_crotl
.
. . _rotl .
_crotr
.
. . _rotl .

349

cscanf
( ).
. . scanf .

cwait
.
process.fi.

#include <process.h>
int c w a i t ( i n t *statloc, int pid,
int w a i t ( i n t * s t a t l o c ) ;

int a c t i o n ) ;

cwait wait , exec... spawn....


wait
. , , .
statloc wait NULL, , .
:
0-7

8-15

.
, exit return main.
main return,

:
0-7

1
2
3

8-15

wait . -1,
EINTR , ECHILD .
cwait wait, .
statloc, , : pid action. pid 0, , . pid . .
action : WAIT_CHILD , WAIT_GRANDCHILD ,
, .

350

. spawn....

Date
.
SysUtils.hpp, DateUtils.hpp.

#include <SysUtils.hpp>
extern PACKAGE S y s t e m : : T D a t e T i m e
extern PACKAGE S y s t e m : : T D a t e T i m e
extern PACKAGE System::TDateTime
extern PACKAGE bool
fastcall

fastcall Date(void);
fastoall Now(void);
fastcall Time(void);

IsToday(const System::TDateTime A V a l u e ) ;

#include <DateUtils.hpp>
extern PACKAGE S y s t e m : : T D a t e T i m e
extern PACKAGE System::TDateTime
extern PACKAGE S y s t e m : : T D a t e T i m e

fastcall Today(void);
f a s t c a l l Tomorrow'(void);
fastcall Yesterday(void);

Date Today
TDateTime. , , 0. Time , , , 0. Now , Date Time.
Tomorrow Yesterday
, . IsToday ,
AValue .
, ,
DateToStr. TimeToStr. DateTimeToStr. DateTimeToString
. DecodeDate . , , , ..

Editl->Text = " " + D a t e T o S t r ( D a t e ( ) ) ;

Editl " 25.05.02".

AnsiString D a y s [ 7 ] = {"", "", "",


"", "", "", ""};
Editl->Text = " " + DateToStr (Date ( ) ) + " (" +
Days[DayOfWeek(Date())-1] + ")";
Editl " 25.05.2002 ()".
DayOfWeek. , DayOfTheWeek. Days:
A n s i S t r i n g D a y s [ 7 ] = ("", "", "",
"", "", "", ""};
Editl->Text = " " + D a t e T o S t r ( D a t e ( ) ) + " (" +
Days[DayOfTheWeek ( D a t e ( ) ) - ! ] + " ) " ;

Editl->Text = D a t e T i m e T o S t r ( N o w ( ) ) ;
Editl "25.05.2002 14:35:49".

351

Editl->Text = DateTimeToStr(Date());

Editl "25.05.2002".

Editl->Text = " " + T i m e T o S t r ( T i m e ( ) ) ;

Editl " 14:38:26".


, - , :
TDateTime Tl = Time ;
<, >
Editl->Text = " " + T i m e T o S t r ( T i m e ( ) - T l ) ;

Editl " 0:01:25".

DateTimeToStr
.
. . DateToStr
.

DateTimeToString

.
SysUtils.hpp.

extern PACKAGE void


fastcall
DateTimeToString(AnsiString ^Result,
const AnsiString Format,
System::TDateTime DateTime);
extern PACKAGE AnsiString
fastcall
FormatDateTime(const AnsiString Format,
System::TDateTime DateTime);

DateTimeToString Result, FormatDateTime , , Format, , DateTime TDateTime. :

, ShortDateFormat (". . ", ) ,


LongTimeFormat ("::"). DateTime , .

: 1-31.

dd

, : 01-31.

ddd

, ShortDayNames.
Windows : "", "", "", "",
"", " ", "".

352


, dddd
LongDayNames: ""
"".
, ddddd
ShortDateFormat: ". . " ( ).
, dddddd
LongDateFormat: , , ( ".").
: 1-12.

m h
hh, , : 0-59.
mm
: 01-12. m h hh, , : 00-59.
,
mmm
ShortMonthNames: ""
"".
, mnimm
LongMonth Names: ""
"".

'

:
00-99.

: 0000-9999.

: 0-23.
h
hh
n

nn
s

ss
z
zzz

t
tt
am/pm
a/p

: 00-23.
: 0-59.
: 00-59.
: 0-59.
: 00-59.

: 0-999.
:
000-999.
, ShortTimeFormat (":").
, LongTimeFormat ("::").
12-
"am" "". , .
12- "" "". , .

353

a in pin

12 - , TimeAMString TimePM String ( Windows ).

, DateSeparator ( "/")

, TimeSeparator (":").

''/""

, ,
, , .

. Format , ,
"".

, .

27.09.00 21:00:11

27.09.00 21:00:11

27.09.00 21:00:11

d mmmm yyy

27 2000

dddddd

27 2000 .

h . m .

21 . 0 .

Editl->Text = FormatDateTime(" h . m .", Now ( ) ) ;

Editl , .

A n s i S t r i n g S;
DateTimeToString(S, " d mmmm yyy ", N o w ( ) ) ;
" 25 2002 ".

DateToStr
.
SysUtils.hpp.

extern PACKAGE AnsiString fastcall


DateTimeToStr(const System::TDateTime DateTime);
extern PACKAGE AnsiString
fastcall
DateToStr(const System::TDateTime DateTime);

354

4
extern PACKAGE AnsiString
fastcall
TimeToStr(const System::TDateTime DateTime);

DateTimeToStr , , DateTime TDateTime.


DateTime , ,
, . , DateToStr , , TimeToStr , .
, ShortDateFormat, , LongTimeFormat. Windows ".." ":
:".
Da'teTimeToString FormatDateTime.
. . Date .

DayOf
.
DateUtils.hpp.

#include <DateUtils.hpp>
extern PACKAGE Word
fastcall
DayOf (const System::TDateTime AValue);
extern PACKAGE Word
fastcall
DayOfTheMonth(const System::TDateTime AValue);
extern PACKAGE Word
fastcall
HourOf(const System::TDateTime AValue);
extern PACKAGE Word
fastcall
HourOfTheDay(const System::TDateTime AValue);
extern PACKAGE Word
fastcall
MilliSecondOf(const System::TDateTime AValue);
extern PACKAGE Word
fastcall
MilliSecondOfTheSecond(constTDateTime AValue);
extern PACKAGE Word
fastcall
MinuteOf(const System::TDateTime AValue);
extern PACKAGE Word
fastcall
MinuteOfTheHour(const System::TDateTime AValue);
extern PACKAGE Word
fastcall
MonthOf(const System::TDateTime AValue);
extern PACKAGE Word
fastcall
MonthOfTheYear(const System::TDateTime AValue);
extern PACKAGE Word
fastcall
SecondOf(const System::TDateTime AValue);
extern PACKAGE Word
fastcall
SecondOfTheMinute(const System::TDateTime AValue);
extern PACKAGE Word
fastcall
YearOf (const System::TDateTime AValue);

AValue TDateTime : (YearOf), (MonthOf, MonthOfTheYear),


(DayOf, DayOfTheMonth), (HourOf, HourOfTheDay), (MinuteOf, MinuteOfTheHour), (SecondOf, SecondOfTheMinute),
(MilliSecondOf, MilliSecondOfTheSecond).
.
, , , .

355

.
DayOfTheMonth, , , DayOfTheWeek, .
.
. DecodeDate DecodeTime.
, , , .

ShowMessage(" " + I n t T o S t r ( Y e a r O f ( N o w ( ) ) ) + " " ) ;


ShowMessage(" " + I n t T o S t r ( D a y O f ( N o w ( ) ) ) + "- " +
I n t T o S t r ( M o n t h O f ( N o w ( ) ) ) + "- " +

IntToStr ( Y e a r O f ( N o w ( ) ) ) + " " ) ;


: " 2002 " " 8- 5-
2002 ".
DayOfTheMonth
.
. . DayOf .
DayOfTheWeek
.
DateUtils.hpp, SysUtils.hpp.

tinclude <DateUtil.s.hpp>
extern PACKAGE Word
fastcall
DayOfTheWeek(const System::TDateTime AValue);
tinclude <SysUtils.hpp>
extern PACKAGE Word
fastcall
DayOfWeek(const System::TDateTime DateTime);

DayOfTheWeek DayOfWeek , , Date TDateTime.


1 7. DayOfTheWeek 1 , 7 - - . ISO 8601.
DayOfWeek 1 , 7 . , .
. . Date .
DayOfWeek
.
. . DayOfTheWeek .
DaysBetween
.
DateUtils.hpp.

#include <DateUtils.hpp>
extern PACKAGE int
fastcall
DaysBetween (const System::TDateTime ANow,
const System::TDateTime AThen);

356

4
extern PACKAGE double
fastcall
DaySpan(const System::TDateTime ANow,
const System::TDateTime AThen);

DaysBetween DaySpan ANow AThen TDateTime. DaysBetween


. DaySpan , , .

TDateTime Tl = EncodeDateTime(2002, 10, 5, 11, 25, 45, 3 0 0 ) ;


TDateTime T2 = EncodeDateTime(2002, 10, 6, 11, 2 4 , 45, 3 0 0 ) ;
int i = DaysBetween(T2, T l ) ;
double r = DaySpan(T2, T l ) ;

i , 0,99930555555.
1 2 EncodeDateTime. 23 59 .
DaysBetween 0, .
DaySpan , .

DaySpan
.
. . DaysBetween
.

DecodeDate
TDateTime
.
SysUtils.hpp, DateUtlls.hpp.

tinclude <SysUtils.hpp>
extern PACKAGE void
fastcall
DecodeDate(const S y s t e m : : T D a t e T i m e DateTime,
Word SYear, Word SMonth, Word & D a y ) ;
extern PACKAGE void
fastcall
DecodeTime(const System::TDateTime DateTime,
Word SHour, Word SMin, Word &Sec,
Word SMSec);
tinclude <DateUtils.hpp>
extern PACKAGE void
fastcall
DecodeDateTime(const S y s t e m : : T D a t e T i m e DateTime,
Word & Y e a r , Word SMonth,
Word &Day, Word sHour,
Word SMin, Word sSec,
Word SMSec);

DateTime TDateTime : Year , Month , Day ,


Hour , Min , Sec , MSec .
DecodeDate DecodeTime . DecodeDateTime , .

357

. , . DayOf .

, Year_b, - , Age :
Word Year, Month, Day, Age, Year_b;
D e c o d e D a t e ( N o w ( ) , Y e a r , Month, D a y ) ;
Age = Year - Year_b;

DecodeDate Year, Month Day , . Year


.
, - , :
Word Hourl, Hour2, Mini, Min2, Seel, Sec2, MSec;

DecodeTime(Time(), Hourl, Mini, Seel, MSec);


<, >

DecodeTime(Time(), Hour2, Min2, Sec2, MSec);


Editl->Text = " " + IntToStr(Hour2 - Hourl) + " , "
+ IntToStr(Min2- Mini) + " , "
+ IntToStr(Sec2- Seel) + " ";

Editl : " ... , ... , ... ".

DecodeDateTime TDateTime
.
. . DecodeDate
TDateTime.
DecodeTime TDateTime
.
. . DecodeDate
TDateTime.
div
, .
stdlib.h, Math.hpp.

tinclude <stdlib.h>
typedef struct {
int quot;
int rem;
} div_t;

//
//

div_t div(int numer, int);


typedef struct {
long int quot;
long int rem;
} ldiv_t;

//
//

Idiv t ldiv(long int numer, long int denom);

358
^include <Math.hpp>
extern PACKAGE void

fastcall
DivMod(int Dividend, Word Divisor,
Word &Result, Word Remainder) ;


. div Idiv numer
denom. div_t Idiv_t . quot ,
rem .
DivMod Dividend Divisor,
Result ( ) Remainder (
Dividend Result * Divisor).

finclude <stdlib.h>
div_t x;
x = div(StrTo!nt(Editl->Text) , StrToInt(Edit2->Text) ) ;

,
Editl Edit2.
:
x.rem

Editl

Edit2

x.quot

10

10

10

.
DivMod(ll, 4, Result, Remainder);
Result = 2 Remainder = 3.

DivMod
, .
. . div .

EncodeDate TDateTime
.
SysUtils.hpp, DateUtlls.hpp.

tinclude <SysUtils.hpp>
extern PACKAGE S y s t e m : : T D a t e T i m e
fastcall
EncodeDate(Word Year, Word Month, Word D a y ) ;
extern PACKAGE bool
fastcall
TryEncodeDate(Word Year, Word Month, Word Day,
System::TDateTime &Date);
extern PACKAGE System::TDateTime
fastcall
EncodeTime(Word Hour, Word Min, Word Sec,
Word MSec);
extern PACKAGE bool
fastcall
TryEncodeTime(Word Hour, Word Min, Word Sec,
Word MSec, System::TDateTime STime);

359

#include <DateUtils.hpp>
extern PACKAGE System::TDateTime
fastcall
EncodeDateTime(const Word Year,
const Word Month, const Word Day,
const Word Hour, const Word Kin,
const Word Sec, const Word MSec);
extern PACKAGE bool
fastcall
TryEncodeDateTime(const Word Year,
const Word Month, const Word Day,
const Word Hour, const Word Min,
const Word Sec, const Word MSec,
System::TDateTirae iValue);

EncodeDate, EncodeTime, EncodeDateTime


TDateTime. Year, Month,
Day, Hour, Min, Sec, MSec. Year 1 9999, Month 1 12, Day 1 28-31
, , , . Hour 0 24, Min Sec 0 59,
MSec 0 999. Hour = 24, Min, Sec, MSec = 0 .
, EncodeDate, , , , EncodeTime,
, . EncodeDateTime , .
EConvertError.
, "Try", ,
(Date, Time Value). : , false.

TDateTime 25 1917 :
TDateTime = EncodeDate(1917, 10, 2 5 ) ;
:
TDateTime ;

TryEncodeDate(1917, 10, 25, ) ;

:
Word Year = 1917, Month = 10, Day = 32;

TDateTime = EncodeDate(Year, Month, Day);
(Day 32),
TDateTime ;
TryEncodeDate(Year, Month, Day, ) ;
.
EncodeDate :
try

TDateTime = EncodeDate(Year, Month, Day);


)
catch(EConvertError &)
{
ShowMessage(" ");

360

TryEncodeDate :
if

(! TryEncodeDate(Year, Month, Day, ) )


ShowMessage(" " ) ;

TDateTime 17 45 : ,
TDateTime = EncodeTime(17, 45, , ) ;
:
TDateTime ;
TryEncodeTime(17, 45, , , );

EncodeDateTime TDateTime
.
. . EncodeDate TDateTime.
EncodeTime TDateTime
.
. . EncodeDate TDateTime.
EnsureRange ,
, .
Math.hpp.

extern PACKAGE int

fastcall EnsureRange(const int AValue,


const int AMin, const int AMax);
extern PACKAGE
int64
fastcall EnsureRange(
const
int64 AValue, const
int64 AMin,
const
int64 AMax);
extern PACKAGE double
fastcall EnsureRange(
const double AValue, const double AMin,
const double AMax);

EnsureRange , AValue AMin AMax.


AValue , AValue.
AValue < AMin, AMin. AValue > AMax, AMax.
,
EnsureRange(5, 1, 10); // 5
EnsureRange(11, 1, 10); // 10
EnsureRange(0, 1, 10); // 1

exec...
.
process.h.

#include <process.h>
int execl(char *path, char *argO *argl, ..., *argn, NULL);
int _wexecl(wchar_t *path, wchar_t *argO *argl, ..., *argn, NULL);
int execle(char *path, char *argO, *argl, ...,
*argn, NULL, char **env);

_^

361

int _wexecle(wch,ar_t *path, wchar_t *argO, *argl, ...,


*argn, NULL, wchar_t **env);
int execlp(char *path, char *argO,*argl, ...,
*argn, NULL);
int _wexeclp(wchar_t *path, wchar_t *argO,*argl,
*argn, NULL);

...,

int execlpe(char *path, char *argO, *argl, ...,


*argn, NULL, char **env);
int _wexeclpe(wchar_t *path, wchar_t *argO, *argl,
..., *argn, NULL, wchar_t **env);
int execv(char *path, char *argv[]);
int _wexecv(wchar_t *path, wchar_t *argv[]);
int execve(char *path, char *argv[], char **env);
int _wexecve(wchar_t *path, wchar_t *argv[],
wchar_t **env);
int execvp(char *path, char *argv[]);
int _wexecvp(wchar_t *path, wchar_t *argv[]);
int execvpe(char *path, char *argv[], char **env);
int _wexecvpe(wchar_t *path, wchar_t *argv[],
wchar_t **env);

exec... path, . . , .
exec... ,
:
argO, argl, ...,
argn. , .
argv[] argO, argl, ..., argn. , .
, PATH. path , ,
, PATH.
"", .
env, . "", .
exec...
(argO), path. , .
( , )
128 .

362

"1"
. .
NULL, .
"v"
, , .
NULL, , .
"" env , .

<_> = <>

env = NULL, "" , ,


.
, , . ,
( ).
, .
path, exec..., . path
, , . , , . , . . ,
.com . "" (
path). "" , , PATH.
0 ,
1.
EACCES , EMFILE
, ENOENT , ENOEXEC , ENOMEM .
, cwait wait.
,

. : ,
exec... .
. . , .
, exec...:
- ,
,

spawn... (. . spawn... ),
,
.

363

i f ( e x e c l ( " F l . e x e " , " F l . e x e " , NULL))

ShowMessage(" Fl.exe ");


Fl.exe. .
execl -1 ShowMessage. , , , Fl.exe
.

execlp("nc","nc", NULL);
Norton Commander ( .),
PATH.

char * prog = "command.com";


execlp(prog,prog, NULL);

DOS, command.com PATH.

execlp("Winword","Winword",

"F.doc",NULL))

Word F.doc.
Word :
char *arg[5] = { " W i n w o r d " } ; //
arg[l] = "Fl.doc";
arg[2] = "F2.doc";
execvp(arg[0],arg);

arg
"Winword", - NULL. 1 2
Word . NULL.
execvp Winword
.
fabs, fabsl
.
. . abs .
fgetc /
.
stdio.h, conio.h.

ttinclude <stdio.h>
int fgetc (FILE *stream);
wint_t fgetwc(FILE * stream);
int fputc(int c, FILE *stream);
wint_t fputwc(wint_t c, FILE * stream);
int getc(FILE *stream);
wint_t getwc(FILE *stream);

364

4
int putc(int c, FILE * stream);
wint_t putwc(wint_t c, FILE *stream);
int getchar(void);
wint_t getwchar(void);
int _fgetchar(void);
wint t _fgetwchar(void);
int putchar(int c);
wint_t putwchar(wint_t c) ;
int _fputchar(int c) ;
wint_t _fputwchar(wint_t c);
int ungetc(int c, FILE *stream);
wint_t ungetwc(wint_t c, FILE *stream);
#include <conio.h>
int getch(void);
int getche(void);
int ungetch(int ch) ;

fgetc fgetwc stream. .


, EOF. stream
stdin,
. . :
#include <stdio.h>
finclude <string.h>
int m a i n ( v o i d )
{
char s [80], ch;
m e m s e t f s , ' \0 ', s i z e o f ( s ) - 1);
do s [ s t r l e n ( s ) ] = f g e t c ( s t d i n ) ;
while ( s [ s t r l e n ( s ) - l ] ! = ' . ' ) ;
puts (s) ;
fflush(stdin);
fgetc(stdin);
}

memset s. do ... while fgetc


s. , , strlen.
,
puts. , DOS , . fflush , fgetc , Enter.
fgetc . , . - Enter,
fgetc , ( )
( while ),
. s. fgetc
. fgetc

365

, , DOS ,
Enter.
fgetc Windows , , .
, , input.txt , "$" ".". :
char s [ 2 5 6 ] , ch;
memset(s, ' \ 0 ' , s i z e o f ( s ) - 1);
FILE *F;
F = fopen("input.txt", "rt");
while ( f g e t c ( F ) ! = ' $ ' ) ;
do s [ s t r l e n ( s ) ] = f g e t c ( F ) ;
while ( s [ s t r l e n ( s ) - 1 ] ! = ' . ' ) ;
ShowMessage(s);
fclose(F);

while
, "$". do ... while
s .
getc getwc fgetc fgetwc.
, getc getwc , .
getchar getwchar , stdin getc(stdin) getwc(stdin).
Win32 . _fgetchar
_fgetwchar , fgetc(stdin) fgetwc(stdin)
.
getch ,
.
, - () . , . getch
, .
Win32
. , ,
.
( MyClose), , DOS. , . CharToOem.
getch, .
#include <stdio.h>
#include <system.hpp>
void M y C l o s e ( v o i d )
{
char S[] = " ";
CharToOem(S, S ) ;
puts ( S ) ;
getch () ;
}


MyClose () ;

366

getche , getch, . , , . , : 1, 2 3. :
switch ( g e t c h e ( ) )
{
' : . . .
break;
case ' 2 ' : . . .
break;
case ' 3 ' : . . .
break;
default : . . .
}

,
.
fputc fputwc stream . stdout, , . , ,
:
char *S = "Hello world";
f o r f i n t i=0; i <strlen ( S ) ; i++)
{ f p u t c ( S [ i ] , s t d o u t ) ; Sleep ( 5 0 0 ) ; }

( 500 .
Sleep) S. ,
putchar putwchar,
stdout . fputc :
putchar(S[i]);

putc putwc fputc fputwc, . _fputchar _fputwchar , fputc(c, stdout) fputwc(c, stdout). Windows.
ungetc ungetwc stream,
. ,
( ) . ungetch
.
,
. , fgetc ,
"$". , "$" , do :
t
ungetc('$', F);
fgetc .
ungetc ungetch ,
stdin ( ) ch,
: ungetc(ch, stdin) ungetch(ch),
getc fread.
ungetc ungetch
.

367

, ungetc, ungetwc, ungetch


.
getc , . , fflush, fsetpos, rewind , ungetc, ungetwc, ungetch.
_fgetchar
.
. . fgetc / .
fgets
.
. . fputs / .
fgetwc
.
. . fgetc / .
_fgetwchar
.
. . fgetc / .
fgetws
.
. . fputs / .
FindClose
, FindFirst.
. . FindFirst ++ilder.
FindExecutable API Windows
, .
ShellAPI

HINSTANCE FindExecutable(
LPCTSTR IpFile,
//
LPCTSTR IpDirectory,
//
LPTSTR IpResult
//

);

FindExecutable .,
, IpFile. IpDirectory . . IpResult
, , IpFile.
FindExecutable ,
32. , .

368

char A P c h a r [ 2 5 4 ] ;

FindExecutable("Doc.do",NULL,APchar);
, APchar ,
Doc.doc, :
C:\\PROGRAM FILESX\MICROSOFT OFFICE\\OFFICE\\WINWORD.EXE
, Doc.doc .
FindExecutable GetLastError. 32,
. , , :
int i = G e t L a s t E r r o r ( ) ;
if (i <= 32)
ShowMessage(" . " + I n t T o S t r ( i ) ) ;

findfirst
, .
dir.h.

tinclude <dir.h>
struct ffblk {
long
long
unsigned long
unsigned short
unsigned short
char
struct _wffblk {
long
long
unsigned long
unsigned short
unsigned short
wchar t

ff reserved;
ff_fsize;
ff_attrib;
ff_ftime;
ff_fdate;
ff name[256];

//
//
//
//
//
//
//

ff_reserved;
ff_fsize;
ff_attrib;
ff_ftime;
ff_fdate;
ff name[256];

Win32

//
//
//
//
//
//
//

Unicode

int findfirst(const char *pathname, struct ffblk *ffblk, int attrib);


int __wfindfirst(const wchar_t *pathname,
struct _wffblk *ffblk, int attrib);
int findnext(struct ffblk *ffblk);
int _wfindnext(struct _wffblk *ffblk);

findfirst findnext, Unicode _wfindfirst


_wfindnext, , .
findfirst. pathname
. , pathname = "c:\\test\\*.*", c:\test\. pathname = "c:\\test\\*.tmp",
c:\test\ .tmp. pathname =
"*.tmp", .tmp .

369

Attr ,
:
FA_RDONLY
FA_HIDDEN
FA_SYSTEM
FAJLABEL
FA_DIREC
FA_ARCH

. , Attr = FA_RDONLY | FAJHIDDEN,


.
0, , , . ,
-1, ENOENT, _doserrno ENMFILE, , ENOENT,
.
, ffblk,
ffblk. ff_name
. , "Test.txt". ff_ftime ff_fdate
.
16- , :

0-4

5-10
11-15

ff ftime
, 2
(.. 1 2 .)

ffjdate

, 1980
(, 22 2002 .

ftime, io.h.
ff_attrib ffblk .
ffblk
(&). ,
. , , ,
( f f b l k . f f _ a t t r i b & FA__SYSTEM)

0, .
, findfirst ,
, , .
findncxt ffblk , findfirst. findfirst 0, , , . ffblk,
findfirst . findfirst
, , , .

C++Builder, . FindFirst
C++Builder.

370

Memol , c:\My.
#include <dir.h>
struct ffblk F;
int ires = findfirst ("c: \\My\\*. *", &F, FA_DIREC | FA_ARCH) ;
Memol->Clear () ;
while ( ! ires)
{
if ( F . f f _ a t t r i b & FA_DIREC)
Memol->Lines->Add (" \t" + AnsiString (F. ff_name) ) ;
else Memol->Lines->Add (" \ t " + AnsiString (F. f f_jiame) ) ;
ires = f indnext ( & F ) ;
}

myexitl (. . 1.12.2), .tmp:


finclude <dir.h>
#include <stdio.h>
void myexitl (void)
{
struct ffblk ffblk;
int D;
D = findfirst ("*. tmp", sffblk, 0) ;
while (!D)
{
remove (ffblk. ff^name) ;
D = f indnext (Sffblk) ;

FindFirst C++Builder
, .
SysUtils.hpp.

#include <SysUtils .hpp>


struct TSearchRec
{

int Time;
//
int Size;
//
int Attr;
//
AnsiString Name; //
int ExcludeAttr;
int FindHandle;
_WIN32_FIND_DATAA FindData;
);
extern PACKAGE int _ fastcall
FindFirst (const AnsiString Path, int Attr, TSearchRec &F) ;
extern PACKAGE int _ fastcall FindNext (TSearchRec SF) ;
extern PACKAGE void _ fastcall FindClose (TSearchRec &F) ;

FindFirst, FindNext FindClose , .

371

FindFirst. Path
. , Path = "c:\\test\\*.*",
c:\test\. Path = "c:\\test\\*.tmp", c:\test\ .tmp. Path = "*.tmp",
.tmp .
Attr ,
:

faReadOnly

$00000001

i284faffidden

$00000002
$00000004

$00000008

faArchive

$00000010
$00000020

faAnyFile

$0000003F

faSysFile
faVolumelD
faDirectory

. , Attr = faReadOnly + faHidden,


.
0, , , . .
, TSearchRec, F. Name
. , "Test.txt". Time
. DOS.
TDateTime FileDateToDateTime, ,
DateTimeToStr. ,
DateTimeToStr(FileDateToDateTime(F.Time))

.
Attr F .
Attr
(|). , 0. , , ,
(F.Attr & faSysFile)

true, .
, FindFirst ,
, , .
FindNext
F , FindFirst. FindNext 0, , . F, FindNext . FindNext
, , .
FindClose F.
, .

372


, . findfirst .

Memol:
TSearchRec sr;
Memol~>Clear() ;
if (! FindFirst("*.*", faAnyFile I faDirectory, sr)}
{
Memol->Lines->Add(sr.Name + ", : " + IntToStr (sr.Size));
while (! FindNext(sr))
Memol->Lines->Add(sr.Name + ", : " + IntTcStr (sr.Size));
}
FindClose(sr);

c:\MyTemp
.tmp. (. . 1.12).
TSearchRec sr;
int D;
D = FindFirst(".-\\MyTemp\\*.tmp", faAnyFile, sr) ;
while (!D)
{
DeleteFile(sr.Name);
D = FindNext(sr);
}
FindClose(sr);

.
Buttonl .tds:
void
f a s t c a l l TForml: .-ButtonlClick (TObject *Sender)
{
AnsiString CurDir = GetCurrentDir();
TSearchRec sr;
if (! FindFirst("*.*", faAnyFile I faDirectory, sr))
{
if(! CompareText(ExtractFileExt(sr.Name),".tds"))
DeleteFile(sr.Name);
else if((sr.Attr == faDirectory)&&(sr.Name !=".")
&&(sr.Name !=".."))
{
SetCurrentDir(ExtractFileDir(sr.Name));
ButtonlClick(Sender);
SetCurrentDir(CurDir);
}
while (FindNext (sr) == 0)
i
if(! CompareText(ExtractFileExt(sr.Name) , ".tds"))
DeleteFile(sr.Name);
else if((sr.Attr == faDirectory)&&(sr.Name !=".")
&&(sr.Name !=".."))
{
SetCurrentDir (sr.Name);
ButtonlClick (Sender);
SetCurrentDir (CurDir);

FindClose(sr);

373

FindNext
, FindFirst.
. . FindFirst ++ilder.

findnext
, findfirst.
. . findfirst .

FindWindow API Windows


API Windows, , .
winuser.

,
HWND F i n d W i n d o w ( c o n s t char *lpClassName, const char *lpWindowName);

FindWindow , IpClassName IpWindowName. IpClassName , . IpWindowName ,


( Caption , ). NULL, , .
, , . NULL.
, .
, , , . , ,
HWND = FindWindow("TForml"," 2");

, TForml, Caption - " 2".


, , ,
, , . - C++Builder WinSight 32 (
...\Program Files\Borland\CBuilder6\Bin\ws32.exe). , WinSight 32, Spy | Find Window
, Windows. , ,
.
, ,
"{ }"
. , ,
WinSight 32 , SciCalc. ,
:

374

4
HWND H = F i n d W i n d o w C ' S c i C a l c " , " ^ " ) ;

(. . PostMessage).
GetNextWindow API Windows.
FloatToStr
.
SysUtils.hpp

extern PACKAGE AnsiString

fastcall FloatToStr(Extended V a l u e ) ;

FloatToStr Value .
Value . 15 . ,
.
,
"NAN". , ,
"INF" () "-INF" ( ).
, FloatToStrF FloatToText.

S , a R ,
S = FloatToStr(R);

R:
R

-3

-3

5.120

520

sqrt(2)

1,4142135623731

15000

INF

FloatToStrF
, ,
.
SysUtils.hpp.

enum TFloatFormat

f f G e n e r a l , ffExponent, f f F i x e d ,
ffNumber, ffCurrency };
extern PACKAGE A n s i S t r i n g
fastcall FloatToStrF(
Extended V a l u e , TFloatFormat
int Precision, int D i g i t s ) ;

Format,

FloatToStrF Value , Format, Precision Digits.

375

Value . Format :
ffGeneral

ffExponent

ffFixed

ffN umber

ffCurrency

. . 3.1.3.4,
TFloatFormat.
Precision . Precision 7 Single,
15 Double, 18 Extended.
Digits Format . . TFloatFormat . 3.1.3.4.
,
"NAN". , ,
"INF" () "-INF" ( ).

S , a R ,
S = FloatToStrF(R,ffGeneral,7,0);

R:
R

-3

_Q

5.120

520

sqrt(2)

1,414214

15000

INF

FloatToStr. 2 7: 1,414214. , ffGeneral


.

floor, Floor, floorl


.
. . Ceil .

fmod, fmodl
.
math.h.

tinclude <math.h>
double fmod(double x, double y) ;
long double fmodl(long double x, long double y);

376

t i n c l u d e <math.h>
Edit3->Text = f m o d ( S t r T o F l o a t ( E d i t l - > T e x t ) ,
StrToFloat(Edit2->Text));

,
Editl Edit2. EditS. :
Editl

Edit2

EditS

10

10

3,5

11

3,5

0,5

Format
, , .
SysUtils.hpp.

#include <SysUtils.hpp>
extern PACKAGE A n s i S t r i n g
fastcall
F o r m a t ( c o n s t A n s i S t r i n g Format,
const S y s t e m : : T V a r R e c * A r g s ,

const int A r g s S i z e ) ;

, Args TVarRec. Args_Size , .. 1


. Format , . 3.1.2.3.
Args Args_Size
EXISTINGARRAY OPENARRAY (. . 2.11.3)
.
. EConvertError.

A n s i S t r i n g s;
TVarRec A r g s [ 3 ] = {11, -l.le+08, 0 . 0 0 0 1 1 } ;
s = F o r m a t ( " : %d %g % f " , Args, 2 ) ;

s, , Args,
. , 3, Format
2 , 1
. , , ,
, 1.
s ": ", "%d",
"%g", "%f", (
).

377

:
s = F o r m a t ( " % d %g %f % 0 : 1 0 d %10g % 1 0 . 5 f " , A r g s , 2 ) ;

s
"%d", "%g", "%f". "%0:10d"
, . 10, 5.

EXISTINGARRAY:
s = Format("%d % %f %0:10d %10 %10.5f",EXISTINGARRAY(Args));

,
Format OPEN ARRAY:
s = Format("%d %g %f %0:10d %10g %10.5f",
OPENARRAY(TVarRec,( 11, -l.le+08, 0.00011)));

FormatDateTime
.
. . DateTimeToString .

fprintf
, ,
.
stdio.h, conio.h.

tinclude <stdio.h>
int p r i n t f (const char * f o r m a t [ , argument, . . . ] ) ;
int w p r i n t f ( c o n s t wchar_t * f o r m a t [ , a r g u m e n t , . . . ] ) ;
int v p r i n t f ( c o n s t char *format, va_list a r g l i s t ) ;
int v w p r i n t f (const wchar_t * format, v a _ l i s t a r g l i s t ) ;
int f p r i n t f (FILE *stream,
const char * f o r m a t [ , argument, . . . ] ) ;
int f w p r i n t f ( F I L E *stream,
const wchar_t * f o r m a t [ , argument, . . . ] ) ;
int v f p r i n t f (FILE *stream, const char *format,
va_list a r g l i s t ) ;
int v f w p r i n t f ( F I L E *stream, const wchar_t *format,
va_list a r g l i s t ) ;
int s p r i n t f ( c h a r * b u f f e r ,
const char * f o r m a t [ , argument, . . . ] ) ;
int s w p r i n t f ( w c h a r _ t * b u f f e r ,
const wchar_t * f o r m a t ! , argument, . . . ] ) ;
int vsprintf(char * b u f f e r , const char *forraat,
va_list a r g l i s t ) ;
int v s w p r i n t f ( w c h a r _ t * b u f f e r , const wchar_t * format,
va_list a r g l i s t ) ;
tinclude <conio.h>
int cprintf (const char * f o r m a t ! , argument,

...]');

378

. , argument,
. format . , "%", . . 3.1.3.1. , "%i"
, "%g" , "%s" - .
printf wprintf stdout (. . 2.10.3). format
, argument, .
.
, EOF.
, stdout . :
tinclude <stdio.h>
void main(void)
{
int I = 10;
double A = 5.1;
char S[] = "string";
printf("Output with p r i n t f \ n " ) ;
p r i n t f ( " I = %i S = %s A = %g \ n " , I, S, A ) ;
getchar();

:
Output with printf
I = 10 S = string A = 5.1

- . . . CharToOem, CharToOemBuff DOS.


cprintf printf
. ,
BIOS _directvideo. , cprintf "\" "\\" "\t" .
printf wprintf ,
stdout.
fprintf fwprintf. , printf, stream ,
. , :
FILE *F;
int I = 10;
double A = 5.1;
char S [ ] = "";
F = fopen("output.txt", "wt");
f p r i n t f ( F , " f p r i n t f \ n " ) ;
if ( f p r i n t f ( F , "I = %i S = %s A = %g \ n " , I, S, A) == EOF)

ShowMessage(" " ) ;
fclose(F);

output.txt :


f p r i n t f
I = 10 S = s t r i n g A = 5.1

379

'

sprintf swprintf ,
, , buffer. .
. , ..
:
char b u f f e r [ 1 0 0 ] ;
int I = 10;
double A = 5.1;
char S [ ] = "";
s p r i n t f ( b u f f e r , " s p r i n t f \ n " ) ;
sprintf(buffer+strlen(buffer),
"I = %i S = %s A = %g \ n " , I, S, A ) ;

sprintf buffer. buffer+strlen(buffer).


.

fputs. :
FILE *F;
F = fopen ("output.txt", "wt");
fputs(buffer, F);
fclose(F);

. , fputs
, fprintf. ,
fprintf. sprintf
fputs, , , , . ,
. , .
fputs
.
,
"v", , , , va list (. . 1.7.5). , . ,
fprintf.
f i n c l u d e <stdio.h>
#include <stdarg.h>
int p r ( F I L E *F,char * f m t , . . . )
{
va_list a r g ;
int cnt;
va_start(arg, fmt);
cnt = v f p r i n t f ( F , f m t , a r g ) ;
va_end(arg);
return(cnt);

380

fprintf ( ) . , ,
, -
fprintf: - , - , ..

fputc
.
. . fgetc / .

_fputchar
.
. . fgetc / .

fputs /
.
stdio.h, conio.h.

#include <stdio.h>
int fputs(const char *s, FILE *stream);
int fputws (const wchar_t *s, FILE *stream);
int puts(const char *s);
int _putws(const wchar^t *s) ;
char *fgets(char *s, int n, FILE *stream);
wchar_t *fgetws(wchar_t *s, int n, FILE *stream);
char *gets(char *s);
wchar_t *_getws(wchar_t *s);
#include <conio.h>
int cputs(const char *str);
char *cgets(char *str);

fputs fputws stream s


.
. .
. EOF.
stream
stdout, . . :
tinclude <stdio.h>
void m a i n ( v o i d )
{
fputs("Hello worldXn",
}

stdout);


CharToOem.
. :
#include <stdio.h>


FILE *F;
F = fopen("output2.txt",

381

"wt");

if ( f p u t s ( " ! ! ! \ n " , F) < 0)


ShowMessage(" " ) ;
fclose(F);

puts _putws ,
stdout. . . - Windows, stdout .
cputs .
, BIOS _directvideo. ,
cputs "\" "\\" "\t" . . Windows .
fgets fgetws stream s.
, - 1
.
s. s. s . s NULL, . input.txt:
tinclude < s t d i o . h >
char S [ 2 5 6 ] ;
FILE *F;
F = fopen("input.txt", "rt");
w h i l e ( f g e t s (S, 256, F ) )
S>
fclose ( F ) ;

gets _getws s
stdin, . . s
. s NULL .
s. . fgets,
. fgets
stream
stdin. gets _getws . Windows stdin
.
cgets str.
"CR/LF",
(. ). , str .

cgets str[0]. str[l]
. str[2].

, .. str[2].

382

cgets Windows.
, . scanf
fprintf .

fputwc
.
. . fgetc / .

_fputwchar
.
. . fgetc / .

fputws
.
. . fputs / .

free
.
. . malloc .

frexp, frexpl, Frexp


2.
math.h math.hpp.

#include <math.h>
double f r e x p (double x, int * e x p o n e n t ) ;
long double frexpl(long double x, int *exponent);
tinclude <math.hpp>
extern PACKAGE void
fastcall
Frexp(Extended X, Extended & M a n t i s s a , int ^ e x p o n e n t ) ;

X 2. .. : X = Mantissa 2exPnent.
exponent, frexp frexpl , Frexp Mantissa.

#include <math.h>
double number;
int exponent;
number = S t r T o F l o a t ( E d i t l - > T e x t ) ;
Edit3->Text = f r e x p ( n u m b e r , Sexponent);
Edit2->Text = exponent;

, Editl,
exponent, Edit2, , EditS.

383

:
X

exponent

0,5

0,5

10

0,625

1.5

0.75

fscanf
.
. . scanf .
fwprintf
.
. . fprintf .
fwscanf
.
. . scanf .
get - ifstream
.
ifstream

char get () ;
bool get(char);
void get(char *, int n, char delim);

get -
ifstream. , .
.

get
(, )
. get EOF, .
get , :
char s [ 8 0 ] , ;
ifstream infile("Test.dat");
if ( linfile)
f
ShowMessage(" ");
return;
}
int i = 0;
while ( ( = i n f i l e . g e t O ) != E O F )
(
i f ( c == ' \ n ' )

384

//
s[i] = 0;
//
i = 0;
}
//
else s[i++] = ;
}
//
inf lie. close () ;

.
"\", s. "\",
, - , . , : ,
. , .
get() -
. , "$" :
while ( ( = i n f i l e . g e t ( ) ) != EOF)
{
if ( == ' $ ' ) break;
if ( = = ' $ ' ) . . .
}


- get (, ) . get ,
; get
, - get.
get
,
while:
while (infile.get () )


- get :
s, delim (
"\").
, , 1 , . , ,
. ,
( ). , get , .

:
char s [80] ;
ifstream infile ("Test .dat") ;
if ( ! infile)

385

ShowMessage (" " ) ;


return

white ( !inf ile.eof ( ) )

i n f i l e . g e t (s, 80) ;
infile.get () ;
//

//
inf lie. close ( ) ;

get . "\" get


(, 80 ). ,

infile.get (s,80) ;

inf ile .get () ;
. ,
.
get , ,
. getline.

Get8087CW

FPU _

FPU.
. . _contro!87 FPU.

getc

.
. . fgetc / .

getch
.
. . fgetc / .

getchar

.
. . fgetc / .

getche

.
. . fgetc / .

GetExceptionMask
FPU.
math.hpp.

386

tinclude <raath.hpp>
enum TFPUException {exInvalidOp, exDenormalized, exZeroDivide,
exOverflow, exUnderflow, exPrecision};
typedefSet<TFPUException, exInvalidOp, exPrecision>
TFPUExceptionMask;
extern PACKAGE TFPUExceptionMask

fastoall
GetExceptionMask(void);
extern PACKAGE TFPUExceptionMask
fastcall
SetExceptionMask(void TFPUExceptionMask Mask);

GetExceptionMask SetExceptionMask FPU (. . 1.9.3). . SetExceptionMask, ,


Mask.
, FPU :
exInvalidOp

exDenormalized

exZeroDivide

exOverflow

exUnderflow

exPrecision

- TFPUExceptionMask
, .
,
C++Builder 6 : Infinity
( ), Neglnfinity ( ), NaN
( ).
: [exDenormalized, exUnderflow, exPrecision], .. , , .
,
- . , , , . ,
OpenGL
.

Mask:
#include <math.hpp>
TFPUExceptionMask Mask;

, Mask
:
Mask = SetExceptionMask(Mask.Clear() ) ;

.

387

1 :
Mask = SetExceptionMask(Mask exInvalidOp
exDenormalized exZeroDivide
exOverflow exUnderflow
exPrecision);

, , .
, , , :
Mask = SetExceptionMask(Mask) ;

, , .
getline - ifstream
.
ifstream

void getline(char *s, int n);


void getline (.char *s, int n, char delim);

getline -
ifstream. , .
getline : s, n delim ( "\"). , , 1 ,
.
, , .
. getline get,
. get , . getline .

getline.
, get,
getline.
char s [ 8 0 ] , ;
ifstream i n f i l e ( " T e s t . d a t " ) ;
if ( ! i n f i l e )
(
ShowMessage(" ");
return;
}
while(!infile.eof ())
(
infile.getline (s,80);
//
if (s[0] != 0) Labell->Caption = s;
}
//
infile.close();

388

GetLastError API Windows


API Windows,
.

DWORD GetLastError(VOID) ;

GetLastError
. . SetLastError.
GetLastError ,
. ,
SetLastError(O),
.
API Win32
, . , FALSE, NULL,
OxFFFFFFFF -1.
32- . 31. 29 , . . , , . .
,
FormatMessage.
WINNT.H Win32 SDK.

- , , :
int i = G e t L a s t E r r o r ( ) ;
if

(i <= 32)

ShowMessage(" " + I n t T o S t r ( i ) ) ;

GetNextWindow API Windows


API Windows,
Z-.

HWND GetNextWindow(
HWND hWnd,
UINT wCmd
);

GetNextWindow Z-. ,
.
hWnd , .
wCmd . wCmd = GW_HWNDNEXT, , . wCmd = GW_HWNDPREV, , .
, . ( wCmd), 0. GetLastError.

389

GetNextWindow ,
GetWindow GW_HWNDNEXT
GW_HWNDPREV.
. . GetWindowText API Windows.

GetPrecisionMode
FPU.
Math.hpp.

enum TFPUPrecisionMode {pmSingle, pmReserved,


pmDouble, pmExtended}
extern PACKAGE TFPUPrecisionMode

fastcall
GetPrecisionMode(void);
extern PACKAGE TFPUPrecisionMode
fastcall
SetPrecisionMode(const TFPUPrecisionMode Precision);

GetPrecisionMode SetPrecisionMode
FPU (. . 1.9.3).
, , TFPUPrecisionMode. SetPrecisionMode,
, Precision.
:
pmSingle

, Single

pmReserved

pmDouble

, Double

pmExtended

, Extended

, FPU, Get8087CW.
Set8087CW. controls?, controlfp.

GetRoundMode

FPU.
Math.hpp.

enum TFPURoundingMode (rmNearest,

rmDown,

rmUp,

rmTruncate)

extern PACKAGE TFPURoundingMode


f a s t c a l l GetRoundMode(void) ;
extern PACKAGE TFPURoundingMode
fastcall
SetRoundMode(const TFPURoundingMode RoundMode);

GetRoundMode SetRoundMode
FPU (. . 1.9.3).
, , TFPURoundingMode. SetRoundMode, ,
RoundMode.

390

:
rmNearest
rmDown
rmUp
rmTruncate


, ..
, ..
, ..

, FPU, Get8087CW.
Set8087CW. _contro!87. controlfp.

gets
.
. . fputs / .

getwc
.
. . fgetc / .

getwchar
.
. . fgetc / .

Get Window API Windows


, ( Z- ).

HWND GetWindow(
HWND hWnd,
UINT uCmd

GetWindow hWnd, uCmd.


uCmd
Windows.
hWnd ,
. uCmd
:
GW_CHILD

Z-, . ' NULL. , .

GW_HWNDFIRST , Z-.

391


GW_HWNDLAST

, Z-.

GW_HWNDNEXT

Z-.

GW_HWNDPREV

Z-.

GW_OWNER

,
.

, / .
, 0. GetLastError.

GetWindowText

API

Windows _ _

API Windows, , , .

int

GetWindowText (
HWND hWnd,
// ,
LPTSTR IpString, //
int nMaxCount
// ,

API Windows GetWindowText , ( ) . .


hWnd . IpString ,
. nMaxCount . ,
.
,
, . , .
GetLastError.
, ,
Windows WM_GETTEXT.

,
Windows . ,
, , SendMessage WM CLOSE.
HWND H =Handle;
char Pen [128] ;
do
H = GetNextWindow(H,GW_HWNDNEXT) ;
GetWindowText (H, Pch, 128) ;
if (CompareText (Pch, "") == )
break;
) while (H != NULL) ;

392

4
if

(H != NULL)
SendMessage(H, WM_CLOSE,0,0);


Handle . , Z-, GetWindowText Pch. .
CompareText. ,
Pch, . , CompareText . , C++ , if :
if( ! CompareText(Pch, ""))

, . ,
, .
H = NULL, .

_getws
.
. . fputs / .

HourOf
.
. . DayOf .

HourOfTheDay
.
. . DayOf .

HoursBetween
.
DateUtils.hpp.

#include <DateUtils.hpp>
extern PACKAGE int
fastcall
extern PACKAGE double

HoursBetween(
const System::TDateTime
const System::TDateTime
fastcall HourSpan(
const System::TDateTime
const System::TDateTime

ANow,
AThen);
ANow,
AThen);

HoursBetween HourSpan
ANow AThen TDateTime. DaysBetween . DaySpan , , .

TDateTime Tl = E n c o d e D a t e T i m e ( 2 0 0 2 ,

10,

5,

11,

00,

45,

300);

393

TDateTime 2 = EncodeDateTime(2002, 10, 5, 11, 59, 4 5 , 3 0 0 ) ;


int i = HoursBetween(T2, T l ) ;
double r = H o u r S p a n ( T 2 , T l ) ;

i , 0,983333333220799.
1 2 EncodeDateTime. 59 .
HoursBetween 0, .
HourSpan , .

HourSpan
.
. . HoursBetween
.

InputBox
,
.
Dialogs.hpp.

linclude <Dialogs.hpp>
extern PACKAGE A n s i S t r i n g
fastcall InputBox(
constAnsiString ACaption, const A n s i S t r i n g APrompt,
const A n s i S t r i n g A D e f a u l t ) ;

InputBox (. . 4.1) ACaption, APrompt -


,
ADefault. ,
. Cancel, Esc, , ADefault,
- .
, -
, , , ADefault. , , , .
, , ,
InputBox InputQuery.

AnsiString Goal = InputBox("",


" ",
"");

, . 4.1, , , "".
. 4.1
, InputBox

Caned

394

InputBox
SelectDirectorv.

InputQuery
, , .
Dialogs.hpp.

#include <Dialogs.hpp>
extern PACKAGE bool
fastcall InputQuery(
constAnsiString ACaption, const AnsiString APrompt,
AnsiString S V a l u e ) ;

InputQuery (. . 4.2)
ACaption, APrompt -
, . Value .
, InputQuery Value .
. 4.2
, InputQuery

,
, 6|!

Cancst

InputQuery true ,
, . ( Esc,
Cancel) false,
Value , InputQuery.
,
, InputQuery
InputBox.

AnsiString ="";
if (I InputQuery(", ",
", ", Name))
ShowMessage(" , ");
else ShowMessage(", " + Name + " ! " ) ;
, . 4.2,
, , , .

InRange
, .
Math.hpp.

extern PACKAGE bool

fastcall InRange(const int AValue,


const int AMin, const int AMax)


extern PACKAGE bool
extern PACKAGE bool

395
fastcall InRange(const
int64 AValue,
const
int64 AMin, const
int64 AMax);
fastcall InRange(const double AValue,
const double AMin, const double AMax);

InRange true,
AValue AMin - AMax, . false,
AValue AMin .
,
L = InRange(5, 1, 10) ;
L = InRange (1, I , 1 0 ) ;
L = InRange (10, 1, 10);

L true,
L = InR
Raan
nggeeddll,, 1, 10) ;
L = IInnR
Raannggee((00,, 1, 10);

L = false.
IntPower
.
. . pow, powl .
IntToStr
.
SysUtils.hpp.

extern PACKAGE AnsiString


extern PACKAGE AnsiString

fastcall IntToStr(int Value);


fastcall IntToStr( int64 Value);

IntToStr Value .
Value . , ,
.

int A = 40000;
int = 40000;
Editl->Text = IntToStr(A * );

Editl "1600000000". 40000 50000, "-1794967296", .. , , IntToStr,


.
Islnfinite
, .
Math.hpp.

#include <Math.hpp>
extern PACKAGE bool

fastcall Islnfinite(const double AValue);

396

Islnfinite , Infinity
Neglnfinity , (. . 1 . 1.9.3). true.
Sign.
:
if

(Islnfinite(X))
if (Sign(X) < 0)
ShowMessage(" ");
else ShowMessage (" " ) ;

, Infinity Neglnfinity .
Islnfinite. , ,

IsNan
, .
Math.hpp.

- extern PACKAGE bool

fastcall IsNan (const double AValue);

IsNan , NaN , (. . 1
. 1.9.3). NaN, true. ,
NaN . IsNan. , NaN
, .

IsToday ,
, .
. . Date .

labs
.
. . abs, labs, fabs, fabsl .

Idexp, Idexpl, Ldexp 2


2 .
math.h math.hpp.

tfinclude <math.h>
double Idexp (double x, int exp);
long double Idexpl (long double x, int exp) ;
#include <math.hpp>
extern PACKAGE Extended

f a s t c a l l Ldexp(Extended X, int e x p ) ;

397

2, .. 2 .
, _matherr ( Idexp) _matherrl ( Idexpl) (. . 3.1.4.4).

Idiv
, .
. . div .

LnXPl
.
. . log .

log
.
math.h math.hpp.

tinclude <math.h>
double log (double x) ;
long double logl(long double x ) ;
double loglO(double x ) ;
long double l o g l O l ( l o n g double x) ;

linclude <math.hpp>
extern PACKAGE Extended
extern PACKAGE Extended
extern PACKAGE Extended
extern PACKAGE Extended

f a s t c a l l LoglO(Extended X) ;
fastcall Log2(Extended X ) ;
fastcall LogN (Extended N, Extended X) ;
f a s t c a l l L n X P l ( E x t e n d e d X) ;


. log logl .
loglO loglOl, LoglO 10. Log2 2. LogN , N. LnXPl , X,
(+1). X 1.
( LnXPl) , EDOM.
, 0, HUGE_VAL ( log loglO), _LHUGE_VAL ( logl loglOl).
ERANGE.
, _matherr _matherrl (. . 3.1.4.4).

loglO, loglOl, logl


.
. . log .

LoglO, Log2, LogN


.
. . log .

398

LowerCase
.
. . AnsiLowerCase .

_lrand
.
. . random .

_lrotl
.
. . _rotl .

_lrotr
.
. . _rotl .

main
C++.

#include <dos.h>
extern int _argc;
extern char **_argv;
extern wchar_t ** _wargv;
extern char ** _environ;
extern wchar_t ** _wenviron;
int
int
int
int
int
int

main ()
main(int argc)
main(int argc, char * argv[])
main(int argc, char * argv[], char * envf])
wmain(int argc, wchar_t *argv[])
_tmain(int argc, _TCHAR *argv[])

main
C++ .
C++ . , ,
, void.
wmain Unicode, Unicode. _tmain , .
argc ,
. , . ,
, argc = 1.
argv , , . env
argv , :
_=
, PATH, COMSPEC ..

399

main .

_argc, _argv _environ.
C++,
return. , C++

return 0;
.


, main. . DOS CharToOem CharToOemBuff (. . CharToOem, CharToOemBuff DOS).
tinclude <stdio.h>
tinclude <stdlib.h>
int main(int argc, char *argv[], char * e n v [ ] )
{
int i;
printfC'The value of argc is %d \n\n", argc);
printf("These are the %d command-line arguments"
" passed to main:\n\n", argc);
for (i = 0; i < argc; i++)
printf ("
argv[%d]: %s\n", i, argv[i]);
printf("\nThe environment string(s) "
"on this system are:\n\n");
for (i = 0; env[i] != NULL; i++)
printf ("
env[%d]: %s\n", i, env[i]);
getchar();
return 0;
}

(, "-v"):
The value of argc is 2
These are the 2 command-line arguments passed to main:
argv [ 0] : :\CBOILDER\TEST.EXE
argv[l]: -v
The environment string (s) on this system are
env[0]: COMSPEC=C:\COMMAND.COM
env[l]: PROMPT=$p $g
env[2]: PATH=C:\SPRINT;:\DOS;:\ CBUILDER

,
main :
#include <stdio.h>
tinclude <stdlib.h>
int m a i n ( / * i n t argc, char *argv[-], char * e n v [ ] * / )
{
int i;
printfC'The value of argc is %d \n\n", _argc);

400

4
printf("These are the %d command-line arguments"
" passed to _argc\n\n", _argc);
for (1 = 0; 1 < __argc; i + + )
printf ("
argv[%d] : % s \ n " , 1, _ a r g v [ i ] ) ;
p r i n t f ( " \ n T h e environment s t r i n g ( s ) "
"on this system a r e : \ n \ n " ) ;
for (i = 0; _environ[i] != NULL; i++)
printf("
env[%d]: %s\n", i, _environ[i]);
getchar ( ) ;
return 0;
}

.
main.
, .

malloc
.
stdlib.h alloc.h.

void
void
void
void

*malloc(size_t size);
*calloc(size_t nitems, size_t size);
*realloo(void *block, size_t size);
free(void *block);

malloc calloc
(. . 1, . 1.11). realloc . free .
new delete, . 1.11.
malloc
(heap) size . .
size = 0, NULL.
calloc nitems , size. , nitems * size. .

. , size = 0,
nitems = 0, NULL.
realloc . heap, block, size. , block , malloc, calloc realloc. block
NULL, realloc , malloc.
size , ,
block, , NULL. ,
size 0 ,
, .
, realloc NULL. ,
. block, .

401

free , malloc, calloc realloc, block.

malloc ,
, - , .
tinclude <stdio.h>
#include <alloc.h>
char *str;
// str - ,
str = (char *) m a l l o c ( 1 0 0 ) ;
//
free(str);


calloc:
str = (char *) c a l l o c ( 1 0 0 , s i z e o f ( c h a r ) ) ;

malloc calloc , , :
str = (char *) realloc (str, 2 0 ) ;

, :
realloc(str, 20);

, NULL (0),
. , , , NULL.
.
MaxIntValue, Max Value
.
Math.hpp.

finclude <Math.hpp>
extern PACKAGE int
fastcall
MaxIntValue(const int * Data, const int Data__Size);
extern PACKAGE double
fastcall
MaxValue(const double * Data, const int Data_Size);

MaxIntValue MaxValue
Data .
Data_Size ,
.
,
= MaxValue(A, 9 9 ) ;


100 , .

. . random
.

402

_mbscpy
.
. . StrCopy .
_mbslwr
.
. . AnsiLowerCase .
_mbsncpy
.
. . StrCopy .
_mbsupr
.
. . AnsiUpperCase .
Mean
.
Math.hpp.

#include <Math.hpp>
extern PACKAGE Extended
fastcall
Mean(const double * Data, const int Data_Size);

Mean (
) Data. Data_Size , . , ,

j=l

,
= Mean(, 99) ;


100 , .
, MeanAndStdDev.

. . random
.
MeanAndStdDev


.

403

Math.hpp.

#include <Math.hpp>
extern PACKAGE void
fastcall
MeanAndStdDev(const double * Data, const int Data_Size,
Extended &Mean, Extended &StdDev);

MeanAndStdDev Data (Data_Size , ) Mean


StdDev. MeanAndStdDev , Mean StdDev. , , ,
.
, Mean
StdDev.
(> 107) .

. . random
.

memccpy
.

.
. . -


.
mem.h, string.h.

void
void
void
^void

*memcpy(void *dest, const void *src, size_t n); <


*_wmemcpy'(void *dest, const void *src, size_t n) ;
*memmove(void *dest, const void *src, size_t n);
*memccpy(void *dest, const void *src,
int c, size t n);
void *memset (void *s, int c, size__t n) ;
void *_wmemset(void *s, int c, size_t n ) ;

memcpy _wmemcpy dest n src.


,
char Sl[] = "12345", S 2 [ ] = " 6 7 8 9 " ;
memcpy(SI, S2, strlen(S2) ) ;

, S1 "67895". ,
. , .
,
memset.
.
(void *),

404

. ,

char * = (char *) merncpy (SI, S2, strle'n (S2 ) ) ;

SI, .
memcpy _wmemcpy . .
memmove , .
.. , -
, -.
memccpy src dest, ,
, .
, dest, . , NULL.
memccpy:
char S[21];
char *Source = ( E d i t l - > T e x t ) . c _ s t r ( ) ;
char *P = (char *)memccpy(S, Source, ' ', 2 0 ) ;
if (P == NULL)
ShowMessage(" 20 ");
else
{

-1) = ' \ 0 ' ;

ShowMessage(" '"+AnsiString(S)+"', "+


IntToStr( - S - 1));
}

S 20 ( ).
Source Editl. Source S
( ), 20- . , memccpy, NULL, . S , 1 ,
, .
.
memset _wmemset s
s. ,
memset(S,

' \ 0 ' , s i z e o f ( S ) - 1);

S .
.
memset(S, ' * ' , s i z e o f ( S ) - 1);
* (S + sizeof ( S ) - l ) = ' \ 0 ' ;

S "*" . - .
( ), , , , . StrCopy .

memmove
.

.
. . memcpy -

405

memset
.

.
. . memcpy -

MessageBox TApplication
, .
Forms

f u n c t i o n MessageBox(Text,

Caption:

PChar;

Flags: Longint):

Integer;

MessageBox Application TApplication, C++Builder.


, ,
ShowMessage. ShowMessageFmt. MessageDlg. MessageDlgPos. CreateMessageDialog. :

( CreateMessageDialog).
MessageBox , . MessageBox API Windows. Text , 255 . . Caption
. 255 , . .
Flags ,
.
.
,

( Windows)

MB_ABORTRETRYIGNORE

Abort (), Retry () Ignore ().

. .

MB_OKCANCEL

Cancel ().

MB_RETRYCANCEL

Retry () Cancel (),

MB YESNO

Yes () No ().

MB_YESNOCANCEL

Yes (), No () Cancel ().

MB ICONEXCLAMATION,
MB ICONW ARMING

(, ).

406

MB ICONINFORMATION,
MB ICONASTERISK

"i" ().

MB_ICONQUESTION

( ).

MB ICONSTOP,
MB ICONERROR,
MB ICONHAND

(,
).

, ( )

MB_DEFBUTTON1

. .

MB_DEFBUTTON2

MB DEFBUTTON3
MB_DEFBUTTON4

.
.

MB APPLMODAL

,
. . . .

MB SYSTEMMODAL , MB_APPLMODAL,
WS_EX_TOPMOST,
,
. , .
( )

MB_HELP

Help (),
F1 Help.

MBJTOPMOST ( WS EX TOPMOST).
,
,
( ) ..
, -
. , :

407

IDABORT

Abort ().

IDCANCEL

Cancel () Esc.

IDIGNORE

Ignore ().

IDNO

No ().

IDOK

IDRETRY

Retry ().

IDYES

Yes ().

, .
if
{

if (Application->MessageBox (
" ?",
" ",
MB_YESNOCANCEL + MB_ICONQUESTION) != IDYES)
DataSet->Cancel ( ) ;
Abort () ;

else
{
Application->MessageBox (" ", "",
MB_ICONSTOP) ;
Abort () ;

. 4.3. ,
, , . 4, MessageDlg MessageDlgPos.
. 4.3
,
Application->MessageBox

> .

:^t j

!1::::1 & \
)

MessageDlg
.

408

4
Dialogs.hpp.

enum TMsgDlgType {mtWarning, mtError, mtlnformation,


mtConfirmation, mtCustom } ;
enum TMsgDlgBtn {mbYes, mbNo, mbOK, mbCancel, mbAbort,
mbRetry, mblgnore, mbAll, mbNoToAll,
mbYesToAll, mbHelp };
tdefine mbYesNoCancel (System::Set<TMsgDlgBtn, mbYes, mbHelp>
() mbYes mbNo mbCancel)
tdefine mbYesNoAHCancel (System::Set<TMsgDlgBtn, mbYes,
mbHelp> () mbYes mbYesToAll
mbNo mbNoToAll mbCancel)
tdefine mbOKCancel (System::Set<TMsgDlgBtn, mbYes, mbHelp> ()
mbOK mbCancel )
tdefine mbAbortRetrylgnore (System::Set<TMsgDlgBtn, mbYes,
mbHelp> () mbAbort mbRetry mblgnore )
tdefine mbAbortlgnore (System::Set<TMsgDlgBtn, mbYes, mbHelp>
() mbAbort mblgnore )
typedef Set<TMsgDlgBtn, mbYes, mbHelp> TMsgDlgButtons;
extern PACKAGE int
fastcall
MessageDlg(constAnsiString Msg, TMsgDlgType DlgType,
TMsgDlgButtons Buttons, int HelpCtx);
extern PACKAGE int
fastcall
MessageDlgPos(constAnsiString Msg, TMsgDlgType DlgType,
TMsgDlgButtons Buttons, int HelpCtx,
int X, int Y);
extern PACKAGE Forms::TForm*
fastcall
CreateMessageDialog (const AnsiString Msg',
TMsgDlgType DlgType,
TMsgDlgButtons Buttons);

MessageDlg . Msg.
DlgType.
:

mtConfirmation

,
(. . 4.4 )
, "i" (.
. 4.4 )
, - (. . 4.4
)
,
(. . 4.4 )

mtlnformation
mtError
mtWarning
mtCustom

.
(. . 4.4 )

AButtons , .
TMsgDlgBtns AButtons ,
. :

409

_
*f "\

1 :J<j )

: .

. 4.4. , MessageDlg MessageDlgPos

mbYes

"Yes"
"No"

mbNo
mbOK
mbCancel

"OK"

mbHelp

"Help"

mbAbort
mbRetry

"Abort"
"Retry"

mblgnore

"Ignore"
"All"

"Cancel"

mbAll

Buttons "", Buttons . ,


Windows.
, ,
, :

mbYesNoCancel

Yes, No Cancel
OK Cancel
Abort, Retry Ignore

mbOkCancel
mbAbortRetrylgnore

TMsgDlgButtons Buttons.
HelpCtx ,
.
F1. , MessageDlg HelpCtx.
MessageDlg ,
. :
mrYes
mr Abort
mrNone
mrNo
mrRetry
mrOk
mrCancel

mrlgnore

mrAll

410

MessageDlgPos, MessageDlg, . X Y.
CreateMessageDialog
. , . Show ShowModal.
ShowModal
, .
DlgType Buttons
TMsgDlgType TMsgDlgButtons .
CreateMessageDialog , .
, , , , . CreateMessageDialog , ,
Free. .
. MessageBox. , ,
.
, , , . ShowMessage .

:
i f ( M e s s a g e D l g ( " ?",
mtConfirmation, TMsgDlgButtons() mbYes mbNo,
0) == m r Y e s )
{
MessageDlg(" ", m t l n f o r m a t i o n ,
TMsgDlgButtons() mbOK, 0 ) ;
Close ( ) ;
}

MessageDlg mtConfirmation
(. . 4.4 ).
Yes, mtlnformation (. . 4.4 ).
(.
. 4.4 4.4 ):
catch ( . . . )
{
MessageDlg(" .", mtError,
TMsgDlgButtons() mbOK, 0 ) ;
MessageDlg(" .", mtWarning,
T M s g D l g B u t t o n s ( ) mbOK, 0 ) ;
}

,
(. . 4.4 ). Yes, Post; No, Cancel; Cancel,
.
switch (MessageDlg(" ?", mtCustom,
mbYesNoCancel, 0 ) )

case mrYes: Tablel->Post ( ) ;


break;
case mrNo : Tablel->Cancel () ;
break;

411

>

case mrCancel : Close ;


}

MessageDlgPos ( " .", mtWarning,


TMsgDlgButtons () mbOK, 0, 250, 0);

( Y = 0)
.
MessageDlgPos (" ! " , mtError,
TMsgDlgButtons () mbOK, ,
BoundsRect . L e f t , BoundsRect .Bottom) ;

,
.
CreateMessageDialog.
TForm * FMess;
FMess = CreateMessageDialog ( " .", mtWarning,
TMsgDlgButtons () mbOK) ;
FMess->Caption = "";

FMess ,
"". (. 4.5)
. 4.4 , ""
"Warning".
FMess->ShowModal () ;
.
FMess->Free () ;
, .
. 4.5

, CreateMessageDialog

MessageDlgPos
.
. . MessageDlg .

MilliSecondOf
.
. . DayOf .

MilliSecondOfTheSecond
.

412

. . DayOf .
MilliSecondsBetween

.
DateUtils.hpp.

finclude <DateUtils.hpp>
extern PACKAGE int
fastcall
MilliSecondsBetween(const System::TDateTime ANow,
const System::TDateTime AThen);
extern PACKAGE double
fastcall
MilliSecondSpan(const System::TDateTime ANow,
const System::TDateTime AThen);

MilliSecondsBetween MilliSecondSpan ANow AThen TDateTime.


.
MilliSecondSpan
.
. . MilliSecondsBetween .
MinlntValue, MinValue
.
Ma.th.hpp.

tinclude <Math.hpp>
extern PACKAGE int
fastcall
MinlntValue (const int * Data, const int Data_Size);
extern PACKAGE double
fastcall
MinValue(const double * Data, const int Data_Size);

MinlntValue MinValue Data . Data_Size , .


,
= MinValue(A, 99) ;


100 , .

. . random
.
MinuteOf
.
. . DayOf .

413

MinuteOfTheHour
.
. . DayOf .

MinutesBetween
.
DateUtils.hpp.

^include <DateUtils.hpp>
extern PACKAGE int
fastcall
MinutesBetween(const System::TDateTime ANow,
const System::TDateTime AThen);
extern PACKAGE double
fastcall
MinuteSpan (const System::TDateTime ANow,
const System::TDateTime AThen);

MinutesBetween MinuteSpan ANow AThen TDateTime.


MinutesBetween .
MinuteSpan ,
, .

TDateTime Tl = E n c o d e D a t e T i m e ( 2 0 0 2 , 10, 5, 11,


TDateTime T2 = E n c o d e D a t e T i m e ( 2 0 0 2 , 10, 5, 11,
int i = MinutesBetween (T2, T l ) ;
double r = MinuteSpan(T2, T l ) ;

00, 00,
00, 59,

300);
300);

i , 0,98333333269693.
1 2 EncodeDateTime. 59 .
MinutesBetween 0, .
MinuteSpan , .

MinuteSpan
.
. . MinutesBetween .

MomentSkewKurtosis
, .
Matli.hpp.

ftinclude <Math.hpp>
extern PACKAGE void
fastcall
M o m e n t S k e w K u r t o s i s ( c o n s t double * Data, const int Data_Size,
Extended &M1, Extended 2, Extended &M3,
Extended SM4, Extended &Skew,
Extended S K u r t o s i s ) ;

MomentSkewKurtosis Ml, M2,


, 4, Skew Kurtosis. -

414

, . Ml
( ), Mean MeanAndStdDev. 2, 4 . -

, , Popn Variance . . = 0. , ,
. MomentSkewKurtosis Skew. 4 . ,
MomentSkewKurtosis Kurtosis, 4, . ,
, 3. . Kurtosis . 3.
Data_Size ,
.

. . random
.

MonthOf

.
. . DayOf .

MonthOfTheYear

.
. . DayOf .

MonthsBetween _
.
DateUtils.hpp.

tinclude <DateUtils.hpp>
extern PACKAGE int _ fastcall
MonthsBetween (const System: : TDateTime ANow,
const System: :TDateTime AThen);
extern PACKAGE double _ fastcall
MonthSpan (const System: : TDateTime ANow,
const System: : TDateTime AThen);

MonthsBetween MonthSpan
ANow AThen TDateTime.
MonthsBetween .
MonthSpan ,
, .

415

, MonthsBetween
MonthSpan 30.4375
. , 01.02 01.03 MonthsBetween
0, , .

TDateTime Tl = EncodeDateTime(2002, 01, 4, 11, 00, 00, 3 0 0 ) ;


TDateTime T2 = EncodeDateTime(2002, 02, 4, 00, 00, 00, 3 0 0 ) ;
int i = MonthsBetween(T2, T l ) ;
double r = MonthSpan(T2, T l ) ;

i 1, 1,00342231348407.
1 2 codeDateTime. (
11 ). - MonthsBetween 1, MonthSpan , .

MonthSpan
.
. . MonthsBetween .

_new_handler
_new_handler , .
. . set_new_handler
.

Norm
.
Math.hpp.

#include <Math.hpp>
extern PACKAGE Extended
fastcall
Norm(const double * Data, const int Data_Size);

Norm : Data. Data_Size , .

. . random
.

Now
.
. . Date .

OemToChar, OemToCharBuff DOS


API Windows, MS-DOS .
winuser.h.

416

finclude <system.hpp>
BOOL OemToChar('
LPCTSTR IpszSrc,
//
LPSTR IpszDst
//
);
BOOL OemToCharBuff(
LPCTSTR IpszSrc,
//
LPSTR IpszDst,
//
DWORD cchDstLength //
);

MS-DOS. ,
, DOS
. DOS.
IpszSrc , . IpszDst ,
. cchDstLength OemToCharBuff , .
, .
, ANSI Unix. , ANSI, , .. IpszSrc IpszDst .
.
CharToOem. .

, , DOS RichEditl, ASCII.


char *S = (char *) malloc ( s i z e o f ( R i c h E d i t l - > T e x t ) ) ;
O e m T o C h a r ( ( R i c h E d i t l - > T e x t ) . c _ s t r ( ) , S) ;
RichEditl->Text = S;
free(S);

S,
RichEditl.
. RichEditl. .

Point
.
Types.hpp Classes.hpp.

#include <Types.hpp>
struct TPoint
{
int x;
int y;
};
extern PACKAGE TPoint
^include <Types.hpp>

fastcall Point (int AX, int AY)

417

struct TSmallPoint
{
short x;
short y;
}
extern PACKAGE Types::TSmallPoint fastcall
SmallPoint(short AX, short AY);

,
AY. C++Builder (.,
, Rect). . .
.
Point TPoint. SmallPoint TSmallPoint, 16- .
. Point . Bounds .
poly, polyl, Poly
.
math.h math.hpp.

t i n c l u d e <math.h>
double p o l y ( d o u b l e x, int degree, double c o e f f s f ] ) ;
long double p o l y l ( l o n g double x, int degree, long double c o e f f s [ ] ) ;
#include <math.hpp>
extern PACKAGE Extended
fastcall
Poly(Extended X, const double * C o e f f i c i e n t s ,
const int C o e f f i c i e n t s _ S i z e ) ;

poly polyl degree


, coeffs:
c o e f f s [ 0 ] + c o e f f s [ l ] * x + . . . + c o e f f s [ d e g r e e ] * ( degree)

Poly . : Coefficients, Coefficients_Size.

poly 1 +
2
3
2* + 3* + 4* = 10:
double a r r a y [ 4 ] = { 1 , 2 , 3 , 4 ) ;
double result = poly (10, 3, a r r a y ) ;

4321.
Poly:
double a r r a y [ 4 ] = { l , 2 , 3 , 4 ) ;
double result = P o l y ( 1 0 , a r r a y , 3 ) ;

418

PopnStdDev
.
Math.hpp.

#include <Math.hpp>
extern PACKAGE Extended
fastcall
PopnStdDev(const double * Data, const, int Data_Size);

PopnStdDev Data.
Data_Size ,
. ,

Jl(A[i]-A) 2 /n,
V i-l

( ) .
, ,
StdDev MeanAndStdDev.
.

. . random
.
PopnVariance
.
Math.hpp.

#include <Math.hpp>
extern PACKAGE Extended
fastcall
PopnVariance(const double * Data, const int Data_Size);

PopnVariance
Data, ..
. Data_Size , .
,
2(A[i]-A) 2 /n,
i-l

( ) .
, , , 1, Variance.

. . random
.
.

419

PostMessage API Windows


API Windows, , , ,
.
winuser.

BOOL PostMessage(
HWND hWnd,
// -
UINT Msg,
//
WPARAM wParam, //
LPARAM IParam //
);

PostMessage
, , , . PostMessage SendMessage.
, . GetMessage PeekMessage.
hWnd , .
HWND_BROADCAST,
, , , , . NULL,
( ) .
Msg . wParam 1 .

. GetLastError.
, hWnd, Find Window.
WM_USER
PostMessage, , . -
, , , , , .
, hWnd = HWND_BROADCAST
, RegisterWindowMessage.

PostMessage(Form2->Handle,WM_CLOSE,0,0);

Form2 WM_CLOSE, .
PostMessage Form2,
Handle. WM_CLOSE ; wParam IParam .

PostMessage(FindWindow("SciCalc",""), WM_CLOSE,0,0);
FindWindow ,
WM_CLOSE. FindWindow SciCalc . Windows .

420

pow, powl
.
math.h math.hpp.

#include <math.h>
double pow(double x, double y ) ;
long double p o w l ( l o n g double x, long double y ) ;
double p o w l O ( i n t p ) ;
long double p o w l O l ( i n t p ) ;
tinclude <math.hpp>

extern PACKAGE Extended


extern PACKAGE Extended

fastcall Power(

Extended Base, Extended E x p o n e n t ) ;


f a s t c a l l IntPower(
Extended Base, int Exponent);

pow powl , .
, HUGE_VAL
( pow) _LHUGE_VAL ( powl).
ERANGE.
, , EDOM.
0 0.
, _matherr _matherrl (. . 3.1.4.4).
Power -- Base
Exponent. Exponent , Maxlnt, Base .
IntPower Base Exponent, Exponent. Base .
powlO powlOl 10, .

powlO, powlOl
.
. . pow, powl .

Power
.
. . pow, powl .

printf
.
. . fprintf .

putc
.
. . fgetc / .

putchar
.

421

. . fgetc / .
puts
.
. . fputs / .
putwc
.
. . fgetc / .
putwchar
.
. . fgetc / .
_putws
.
. . fputs / .
raise
.
. . signal .
rand, randomize, Randomize, RandG
.
. . random .
random
.
stdlib.h, System.hpp, Math.hpp.

#include <stdlib.h>
long _lrand(void);
int rand(void);
int random(int num) ;
void randomize(void);
void srand(unsigned seed);
#include <System.hpp>
extern PACKAGE void
fastcall Randomize(void);
#include <Math.hpp>
extern PACKAGE Extended

fastcall RandG(
Extended Mean, Extended StdDev);

rand , 0 RAND_MAX (Ox7FFFU - 32767). 232 = 4 294 967 296.


. -
,
( )
randomize srand.

422

, 0
N, %. ,
rand () % 101
0 100,
(rand (} % 201) - 100

-100 100.
rand . ,
10. * a n d ( ) / RAND_MAX

,
0 10.
_lrand rand, 64
31
2 0 2 - 1.
random , num,
. ,
, , 0 100,
random(101);

, , %.
RandG , ( )
Mean StdDev.

, . .
. , , ..
. ,
RandG, randomize. - (, OnCreate )
randomize();


.
srand randomize ,
, seed.
RandG Randomize, randomize.
, RandSeed,
System.hpp.

.
double A [ 1 0 0 1 ] ;
long double M, Me, Std, StdD, StdD2, Ml, M2, , 4, Skew,
Kurtosis, MinA, MaxA, V, TV, PV, N, SOS, S, SoS, S2;
//
f o r ( i n t i = 0; i < 1001;
A[i] = RandG(20,4) ;
Me = M e a n ( A , 1 0 0 0 ) ;
V = Variance(A,1000);

423

TV = TotalVariance(A,1000);
MeanAndStdDev(A,1000, , StdD) ;
PV = PopnVariance (A, 1-000) ;
Std = StdDev(A,1000);
StdD2 = PopnStdDev(A,1000);
N = Norm(A,1000);
MomentSkewKurtosis(A,1000,M1,M2,M3,M4,Skew,Kurtosis);
MinA = MinValue(A,1000) ;
MaxA = MaxValue(A,1000);
SumsAndSquares(A, 1000, S,. SoS) ;
SOS = SumOfSquares(A,1000) ;
S2 = Sum(A,1000);

realloc
.
. . malloc .

Rect
TRect.
. . Bounds .

RegisterWindowMessage API Windows


API Windows,
, SendMessage Post Message.
winuser.

UINT RegisterWindowMes'sage (
LPCTSTR IpString
//

);

Register WindowMessage ,
. , SendMessage
PostMessage hWnd = HWND_BROADCAST. ,
. Windows.
LpString ,
.
, OxFFFF. ,
.
RegisterWindowMessage ,
.

WM USER OxTFFF.

_rotl
.
stdlib.h.

424

tinclude
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned

<stdlib.h>
short _rotl(unsigned
short _rotr(unsigned
long Irotl(unsigned
long _lrotr(unsigned
char __crotl(unsigned
char _crotr(unsigned

short val, int count);


short val, int count);
long val, int count);
long val, int count);
char val, int count);
char val, int count);

_rotl, _rotr, _lrotl, _lrotr


val count . _rotl _lrotl , . , _rotl(l, 15)
32768 , 15 . A _rotl(l, 16)
1 , 15 , 1 .
_rotr _lrotr , .
_crotl _crotr
. , _crotl('l',0) 49 "1", a _crotl('l',l)
98 ( ""). ,
(char)_crotl('l",l) "". val 8 val, _rotl.

_rotr
.
. . _rotl .

RoundTo
.
Math.hpp.

typedef Word TRoundToRange;


extern PACKAGE double
extern PACKAGE double

fastcall RoundTo(const double AValue,


const TRoundToRange ADigit);
fastcall SimpleRoundTo(
const double AValue,
const TSimpleRoundToRange ADigit = -2) ;

RoundTo SimpleRoundTo . AValue .


ADigit , .
-37 37 . ,
ADigit = 3, , , 1000 (103).
1
ADigit = -1, , (10" ).
RoundTo SimpleRoundTo , , . RoundTo . SimpleRoundTo
.
. . Ceil, ceil, ceill, Floor, floor, floorl
GetRoundMode, SetRoundMode .

425

AValue

ADigit

RoundTo

SimpleRoundTo

1234567

3
3
-3
-3

1234000

1234000

1234000

1235000

1.235

1.235

-1.235

-1.234

1234500
1.23456
-1.23456

Same Value
.
. . CompareValue .
scanf
( ), , .
stdio.h, conio.h.

#include <stdio.h>
int scanf(const char *format[, address, ...]);
int wscanf(const wchar_t *format[, address, ...]);
int vscanf(const char *format, va_list arglist);
int fscanf(FILE *stream,
const char *format[, address, ...]);
int fwscanf(FILE *stream,
const wchar_t * format!, address, ...]);
int vfscanf(FILE *stream,
const char *format,va list arglist);
int sscanf(const char *buffer,
const char *format[
int s w s c a n f ( c o n s t
const
int v s s c a n f ( c o n s t
const

address, . . . ]

wchar_t * b u f f e r ,
wchar_t * f o r m a t [ , address,
char * b u f f e r ,
char * f o r m a t , va_list a r g l i s t ) ;

#include <conio.h>
int cscanf (char * f o r m a t [ ,

address,

...]);

. get getline - ifstream.


. ,
, , , . , , ,
.. ,
, argument. format . , "%".

426

(. . 3.1.3.2),
, "%d" , "%" , "%s" . "*" "% " . ,
.

scanf wscanf stdin. . format , argument, .
, . , 0. , EOF.
, stdin . :
#include <stdio.h>
int m a i n ( v o i d )
int I;
f l o a t R;
char S [ 8 0 ] ;
p u t s ( " E n t e r integer number, f l o a t number,"
"string:\n") ;
if (scanf ("%d %e %s", SI, &R, &S) < 3)
puts("Wrong input\n");
else p r i n t f C ' Y o u enter %i, %g, %s", I, R, S ) ;
fflush(stdin);
getchar () ;

puts
, .
(
. . CharToOem, CharToOemBuff DOS).
scanf
, ( "%"), ( "%g"), ( "%s"). , . , , , .
DOS, . , , Enter. : "5 5.6 ". I = 5, R = 5.6, S = "". ,
, : "5
5-". "" "", ,
.
"55.6", I = 55, R = 0.6, S =
"". , .
cscanf scanf . scanf , . ,

427

cscanf, ,
.

scanf wscanf
, stdin. fscanf fwscanf.
, scanf, stream , . , :
tinclude <stdio.h>
FILE *F;
int I;

double R;
char S [ 8 0 ] ;
if ( (F = fopen ("input.txt", " r t " ) ) == NULL)
{
ShowMessage(" ");
return;
}
F = fopen("input.txt", "rt");
if (fscanf (F, "%i %le %s ", & I , &R, & S ) < 3)
ShowMessage(" " ) ;
else
ShowMessage("I = " + I n t T o S t r ( I ) + ", R = " +
FloatToStr(R) + ", S = " + S ) ;
fclose(F);

input.txt , .
,
( 3). , -
.
, R
"1". , R double, long,
(. . 3.1.3.2).
- . , , - ,
X = 1 = 1
X = 2 Y = 4

X Y . :
FILE *F;
int i = 0;

double X[10], Y [ 1 0 ] ;
if ( ( F = f o p e n ( " i n p u t . t x t " , " r t " ) ) == NULL)
{

ShowMessage(" ");
return;
}
while (! feof(F))
1
fscanf(F, "%*s %*s %le %*s %*s %le", &X[i], SY[i]);

428

4
fclose(F);

"%*s" .

sscanf swscanf ,
, ,
buffer. .
,
sscanf. ,
:
char S [ 2 5 6 ] ;

while ( ! f e o f ( F ) )
{

fgets(S, 256, F) ;
s s c a n f ( S , "%*s %*s %le %*s %*s %le", & X [ i ] , S Y [ i ] ) ;

fgets S , sscanf. , fgets fscanf, sscanf, ,


, fscanf.
v...

,
"v", , , , va_list. , . , fscanf.
#include <stdio.h>
#include <stdarg.h>
int r e ( F I L E *F,char * f m t ,

...)

va_list arg;
int cnt;
va_start(arg, f m t ) ;
cnt = v f s c a n f ( F , f m t , arg);
va_end(arg);
return(cnt);

fscanf ( ) . , ,
, - fscanf:
- , ..
SecondOf
.
. . DayOf .
SecondOfTheMinute
.
. . DayOf .

429

SecondsBetween
.
DateUtils.hpp.

tinclude <DateUtils.hpp>
extern PACKAGE int
fastcall
SecondsBetween(const System::TDateTime ANow,
const System::TDateTime AThen);
extern PACKAGE double
fastcall
SecondSpan(const System::TDateTime ANow,
const System::TDateTime AThen);

SecondsBetween SecondSpan
ANow AThen TDateTime. SecondsBetween .
SecondSpan ,
, .

TDateTime Tl = EncodeDateTime(2002, 10, 5, 11, 00, 45, 3 0 0 ) ;


TDateTime T2 = EncodeDateTime(2002, 10, 5, 11, 00, 4 6 , 2 9 9 ) ;
int i = SecondsBetween(T2, T l ) ;
double r = SecondSpan(T2, T l ) ;

i 0, 0,998999434523284.
1 2 EncodeDateTime . - (
). SecondsBetween ,
SecondSpan , .

SecondSpan
.
. . SecondsBetween .

SelectDirectory
.
FileCtrl.hpp\

tinclude <FileCtrl.hpp>
extern PACKAGE bool
f a s t c a l l SelectDirectory(
const A n s i S t r i n g Caption,
const W i d e S t r i n g Root, A n s i S t r i n g S D i r e c t o r y ) ;
enum TSelectDirOpt

{sdAllowCreate, sdPerformCreate,
sdPrompt);
typedef Set<TSelectDirOpt, sdAllowCreate, sdPrompt>
TSelectDirOpts;
extern PACKAGE bool
fastcall SelectDirectory(
AnsiString SDirectory,
TSelectDirOpts Options, int H e l p C t x ) ;

430

SelectDirectory
Windows , , .
. .
Windows (), . 4.6. Caption ,
( . 4.6. Root ,
. Root
. SelectDirectory . 4.6
Root = "d:\\". Root ,
(. 4.6 ), .

6)

%XP(D:)
-gj Documents and Settings
FrontPage webs
B-jjJl Program Ftes
I - Adobe
i frfij ahead
i f-fij Borland
I Eb3l CBulder6
I -Q Bin
- DOCUMENTATION
Examples

K
(|
ffi IJ

EMO SYSTEM (:)
* (D:)
* PROG (
-( TESTS (F:)
! 3 ) CDExampD
i Igjj DATABASE
i-Q CURRENCY
::::** DRTRU^F

OK

OK

. 4.6. () () Root

Directory .
true, .
, ,
false.
. , , . :
#include <FileCtrl.hpp>
AnsiString Dir;
i f ( S e l e c t D i r e c t o r y ( " ", "", D i r ) )
Dir = InputBox(" ",
" :", D i r ) ;
else
(
Application->MessageBox(" ",
" ! " , MB_ICONSTOP);
Application->Terminate();

431

SelectDirectory ,
. 4.6 , Root .
, SelectDirectory
true. ,
Input Box. , 4.7 . ,
, . . 4.6 , Application.MessageBox ,
. 4.7 , .
]

|FADATABASE\DBACCESS

1 Cancel

6)

. 4.6.

SelectDirectory. (. 4.8). - ,
. Directory, , . SelectDirectory Directory,
. HelpCtx
, . Options
:
sdAllowCreate

Directory Name (. . 4.8),


, . . ,
.

sdPerformCreate

sdAllowCreate ,
.

sdPrompt

sdAllowCreate. ,
, .
( ) sdPerformCreate Options, . sdPerformCreate ,
.

Options , ,
.
SelectDirectory , :
tinclude <FileCtrl.hpp>
AnsiString Dir = " d : \ \ " ;
if (SelectDirectory(Dir, TSelectDirOpts() sdAllowCreate
sdPerformCreate sdPrompt, 0 ) )

432

. 4.8

JD.\ProgramFiles\Bo[|and\CBijilder6
Files: ("."I

Directories:

I Bin
QDoc
-] DOCUMENTATION
|SSd:[:<p]
OK

Cancel

Options : sdAllowCreate, sdPerformCreate sdPrompt. . 4.8, Help, .


Directory Name ,
, ,
. 4.9. No, . 4.8.
Yes, .

. 4.9

The;

, SelectDirectory . : . 4.8 4.9 . (. 4.9) . , Options [sdAllowCreate, sdPerformCreate]. . - , Options [sdAllowCreate], . . (. 4.8) .
SendMessage API Windows
API Windows, , .
winuser.

LRESULT SendMessage(
HWND hWnd,
// -
UINT Msg,
//
WPARAM wParam, //
LPARAM IParam //

433

SendMessage , , . , . , , , .
SendMessage PostMessage. .
hWnd , .
HWND_BROADCAST,
, , , , .
Msg . wParam 1 .
, , .
, hWnd, Find Window.
, hWnd = HWND_BROADCAST
, RegisterWindowMessage.

SendMessage(Form2->Handle,WM_CLOSE,0,0);

Form2 WM_CLOSE, .
SendMessage Form2,
Handle. WM_CLOSE ; wParam IParam .

SendMessage(FindWindow("SciCalc",""), W M _ C L O S E , 0 , 0 ) ;

FindWindow ,
WM_CLOSE. FindWindow SciCalc . Windows .
. . FindWindow.

set_new_handler

set_new_handler , .
new.h.

typedef void (new * n e w _ h a n d l e r ) ( ) ;

new_handler set_new_handler(new_handler m y _ h a n d l e r ) ;
typedef void ( * p v f ) ( ) ;
pvf _new_handler;

new (. . 1 . 1.11)
, . bad_alloc,
catch. bad_alloc,
, -

434

. _new_handler, set_new_handler. set_new_handler


. . _new_handler C++
C++ 1.2.
myjhandler set_new_handler
. , .
,
void F l ( v o i d )
{
ShowMessage("He ");
exit(1);
}

, , (, OnCreate )
set_new_handler(Fl);


new, bad_alloc, ( ). , .
, new, ,
.
bad_alloc, ,
set__new h a n d l e r ( 0 ) ;

new NULL.
, , NULL , new.
Set8087CW FPU
FPU.
. . _contro!87 FPU.
SetExceptionMask
FPU.
. . GetExceptionMask .
SetPrecisionMode
FPU.
. . GetPrecisionMode .
SetRoundMode

FPU.
. . GetRoundMode .

435

ShellExecute API Windows


.
ShellAPI.

HINSTANCE ShellExecute (
HWND hwnd,
//
LPCTSTR IpOperation, //
LPCTSTR IpFile,
//
LPCTSTR IpParameters,//
LPCTSTR IpDirectory, //
INT nShowCmd
//

);

ShellExecute Windows.
,
. , ,
.doc, Word. , , "file.doc" Word "file.doc". ShellExecute .
, .
ShellExecute

tinclude "ShellAPI.h"

ShellAPI, .
C-l-+Builder .
hwnd , . Handle.
IpOperation , . "open"
() "print" (). 32- Windows
: "explore" () Windows
. IpOperation NULL, "open".
IpFile ,
.
IpParameters , , IpFile
. IpFile , , IpParameters NULL.
IpDirectory , .
nShowCmd . :
SW_HIDE

SW_MINIMIZE

() Z-
.

436

SW MAXIMIZE

() .

SW_RESTOKE

.
, (
, SW_SHOWNORMAL).

SW_SHOW

SW_SHOWDEFAULT


SW_ STARTUPINFO,
CreateProcess , .
Show Window , .

SW_SHOWMAXIMIZED


().

SW_SHOWMINIMIZED


( ).

SW_SHOWMINNOACTIVE ( ). ,
.
SW_SHOWNA

. ,
.

SW_SHOWNOACTIVATE

.
, .

SW_SHOWNORMAL

.
, (
, SW_RESTORE).

SW_RESTORE, . , .
Windows, PIF .. .
ShellExecute DDE . 32, .

"file.doc", ..
Word ( .doc), .
:
ShellExecute(Handle,NULL,"file.doc",NULL,NULL,SW_RESTORE);

, , , IpOperation:
ShellExecute(Handle,"print","file.doc",NULL,NULL,SW RESTORE);

437

.
Word, .doc, file.doc, Word
, file.doc Word.
Windows :
ShellExecute(Handle,"open","Calc",NULL,NULL,SW_RESTORE);
c:\Program Files\Borland:
ShellExecute (Handle,"open","c:\\Program Files\\Borland",
NULL,NULL,SW_RESTORE);

ShellExecute(Handle,"explore","c:\\Program Files\\Borland",
NULL,NULL,SW_RESTORE);
c:\Program Files\Borland.

SHGetFilelnfo
API Windows,
: , , .
ShellAPI.h.

tinclude <ShellAPI.h>
unsigned int SHGetFileInfoA(const char * pszPath,
unsigned long dwFileAttributes,
__SHFILEINFOA *psfi,
unsigned int cbFilelnfo,
unsigned int u F l a g s ) ;

SHGetFilelnfo : , , . , Windows. pszPath


, . dwFileAttributes SHGFI_
USEFILEATTRIBUTES.
0. psfi
_SHFILEINFOA TSHFilelnfo . cbFilelnfo psfi. uFlags . .
psfi :

HICON

ilcon

int

dwAttributes

DWORD

szDisplayName

char 80

szTypeName

char 80

uFlags :

438

SHGFI_ATTRIBUTES
SHGFI_DISPLAYNAME
SHGFI_EXETYPE
SHGFI_ICON

SHGFI_ICONLOCATION
SHGFI_LARGEICON
SHGFI_LINKOVERLAY
SHGFI_OPENICON
SHGFI_PIDL
SHGFI_SELECTED
SHGFI_SHELLICONSIZE
SHGFI_SMALLICON
SHGFI_SYSICONINDEX

SHGFI_TYPENAME
SHGFI
USEFILEATTRIBUTES

. dwAttributes psfi.
.
szDisplayName psfi.
pszPath , (. ).

.
. hlcon psfi, ilcon. .
,
. szDisplayName psfi.
SHGFI_ICON, .
SHGFI_ICON,
.
SHGFI_ICON, , (, ).
, pszPath
ITEMIDLIST, .
SHGFI_ICON,
, .
SHGFI_ICON,
, .
SHGFI_ICON, .
. ilcon psfi.

.
. szTypeName psfi.
, dwFileAttributes.

, uFlags
SHGFI_EXETYPE. SHGetFilelnfo
:
0

LOWORD = NE (17744)
HIWORD = 3.0, 3.5 4.0


Windows

439

LOWORD = MZ (23117)

MS-DOS .EXE, .COM .

HIWORD = 0
LOWORD = (17744)\

Win32

HIWORD = 0
SHGetFilelnfo
. SHGFI_SMALLICON or SHGFI_ICON or SHGFI_
SYSICONINDEX SHGFIJLARGEICON or SHGFIJCON or SHGFI_SYSICONINDEX Windows.

.
, OpenDialogl . :
void _ fastcall TForml : :ButtonlClick (TObject *Sender)
{
TSHFilelnfo fi;
if (OpenDialogl->Execute () )
{
unsigned int W = SHGetFilelnfo (
(OpenDialogl->FileName) .c__str () , 0,
Sfi, sizeof(fi), SHGFI_EXETYPE) ;
if (W == 0)
ShowMessage (" '" + OpenDialogl->FileName +
"' ");
else if ( (LOWORD (W) == 744) && (HIWORD (W) > 0))
ShowMessage (" '" + OpenDialogl->FileName +
"' - Windows");
else if ( (LOWORD (W) == 23111) && (HIWORD (W) == 0))
ShowMessage (" '" + OpenDialogl->FileName +
"' - MS-DOS");
else if ( (LOWORD (W) == 17744) && (HIWORD (W) == 0))
ShowMessage (" '" + OpenDialogl->FileName +
"' - Win32");

. :
TImageList *SmallImages = new TImageList (Forml) ;
TImageList *LargeImages = new TImageList (Forml) ;
void _ fastcall TForml :: FormCreate (TObject *Sender)
(

TSHFilelnfo

fi;

SmallImages->Handle = SHGetFilelnfo ("*.*", 0, & f i ,


s i z e o f ( f i ) , SHGFI_SMALLICON I
SHGFI_ICON I SHGFI__SYSICONINDEX) ;
LargeImages->Handle = SHGetFilelnfo ( " * . * " , 0, & f i ,
s i z e o f ( f i ) , SHGFI_LARGEICON |
SHGFI_ICON I SHGFI_SYSICONINDEX) ;
DrawGridl->ColCount = 10;
DrawGridl->RowCount = ceil (LargeImages->Count / 10);

440

( new)
Smalllmages Largelmages TImageList.
OnCreate Windows. Smalllmages , Largelmages .
TImageList. ,
TDrawGrid , DrawCell :
void

fastcall TForml::DrawGridlDrawCell(T0bje,ct *Sender, int ACol,


int ARow, TRect SRect, TGridDrawState State)

{
SmallImages->Draw(DrawGridl->Canvas, Rect. Lef t + 10, Rect. Top-t-10,
ARow * DrawGridl->ColCount + ACol,true);
}

DrawGridl, OnCreate :
DrawGridl->ColCount = 10;
DrawGridl->RowCount = ceil(SmallImages->Count / 10);

ShowMessage

.
Dialogs.hpp.

#include <Dialogs.hpp>
extern PACKAGE void
fastcall ShowMessage(constAnsiString Msg);
extern PACKAGE void _^fastcall ShowMessageFmt(constAnsiString Msg,
const System: .-TVarRec *Params,
const int Params_Size);
extern PACKAGE void
fastcall ShowMessagePos(.constAnsiString Msg,
int X, int Y) ;


, - .
,
, ..
.
ShowMessage,
. Msg.
.
ShowMessagePos , ShowMessage, X Y.

, . , .
ShowMessageFmt, . Msg (. . 3.1.3.3), Params Params_Size , Msg, . -

441

OPEN ARRAY (. . 2.11.3). ShowMessageFmt :


ShowMessageFmt(Msg,OPENARRAY(TVarRec, ( a r g l , a r g 2 , . . - . ) ) ) ;
,
, MessageDlg. MessageDlgPos CreateMessageDialog. . MessageBox. ,
, .

ShowMessage(" ");
ShowMessageFmt(" %d %d ",
OPENARRAY(TVarRec, ( N 1 , N 2 ) ) ) ;
, . 4.10.
. 4.10

,
ShowMessage (a), ShowMessageFmt ()
ShowMessagePos ()

[Project1

5 .

ShowMessagePos(" ",
Form2->Left, Form2->Top + Form2->Height);
Form2->Close();
Form2 (. 4.10 ),
2.
ShowMessageFmt

.
. . ShowMessage
.
ShowMessagePos

.
. . ShowMessage
.
Sign
.

442
Math.hpp.

extern PACKAGE int


extern PACKAGE int
extern PACKAGE int

_fastcall Sign(const double AValue);


fastcall Sign (const int AValue);
fastcall Sign(const
int64 AValue),

Sign AValue.
:
0

AValue = 0

-1
+1

AValue < 0
AValue > 0

signal
.

#include < s i g n a l . h >


(JJSERENTRY *signal(int sig,
void (JJSERENTRY * f u n c )
(int sig[, int s u b c o d e ] ) ) ) ( i n t ) ;
void signal(SIGUSR1, Handl_SIGUSRl);
int r a i s e ( i n t s i g ) ;

signal sig. raise sig (. . 1, . 1.13).


signal.fi :
SIGABRT

. abort, raise .
_exit(3).

SIGBREAK

Ctrl-Break.

SIGFPE

, ,
, . _exit(l).

SIGILL

. _exit(l).

SIGINT

(,
Ctrl+C). INT 23h.

SIGSEGV

.
_exit(l).

SIGTERM

. _exit(l).

SIGUSR1,
SIGUSR2,
SIGUSR3

( Win32) ! , raise. .

443

signal , . ,
.
signal :
sig func . fane
: SIG_DFL , SIG_IGN , SIG_ERR . :
//
signal (SIGINT, SIG_ERR);

// SIGINT
signal(SIGINT, SIG_IGN);

, . , ,
SIGUSR1. Handl_SIGUSRl.
fptr:
typedef void

(*fptr)(int);

- :
signal(SIGFPE,

(fptr)Handl_SIGFPE);

Handl_SIGUSR SIGUSR1. :
raise(SIGUSR1);


. signal , , SIG_DFL. ,
, signal,

. signal.

Handl_SIGUSRl
SIGUSR1.
linclude <signal.h>
typedef void (*fptr)(int);
void Handl_SIGUSRl(int N)
{

if (...)
i
// :
signal(SIGFPE, (fptr)Handl_SIGFPE);
}
else exit(EXIT_SUCCESS);
}

,
. ,
. , , signal,
. , -

444

SIGUSR1 .

, . , , .

signal (SIGFPE,

(fptr) Handl_SIGFPE) ;

, , OnCreate .
raise
raise (SIGUSR1) ;

SimpleRoundTo

.
. . RoundTo .

Sleep

.
winbase.h.

void Sleep (DWORD dwMilliseconds);

Sleep ()
dwMilliseconds .
.
,
' Sleep (10000) ;
10 .
- ,
. ,
ProcessMessages Application.
, .
:
Sleep (10000) ;
ShowMessage ( "End" ) ;

10 .
: -
, , . :
f o r ( i n t i=l; i <= 100;

Sleep (100) ;

Application->ProcessMessages () ;
}
ShowMessage ("End") ;


10 . 100 Process-

445

Messages, Windows.
:
, ,
..
. . fgetc /
.
Sleep . Windows API. Linux
. Windows, , Linux .
- Timer Windows.
SmallPoint
.
. . Point .
spawn...
.
process..

#include <process.h>
int s p a w n l ( i n t mode, char *path, char * a r g O , a r g l ,
. . . , argn, N U L L ) ;
int _wspawnl (int mode, wchar_t *path, wchar_t *argO,
argl, ..., argn, NULL);
int spawnle(int mode, char *path, char *argO, argl,
..., argn, NULL, char *envp[]);
int wspawnle(int mode, wchar_t *path, wchar_t *argO,
argl, ..., argn, NULL, wchar_t *envp[]);
int spawnlp(int mode, char *path, char *argO, argl,
..., argn, NULL);
int wspawnlp(int mode, wchar_t *path, wchar_t *argO,
argl, ..., argn, NULL);
int spawnlpe(int mode, char *path, char *argO, argl,
..., argn, NULL, char *envp[]);
int _wspawnlpe(int mode, wchar_t *path, wchar_t *argO,
argl, ..., argn, NULL, wchar_t *envp[]);
int spawnv(int mode, char *path, char *argv[]);
int _wspawnv(int mode, wchar_t *path,
wchar_t *argv[]);
int spawnve(int mode, char *path, char *argv[],
char *envp[]);
int _wspawnve(int mode, wchar_t *path,
wchar_t *argv[], wchar_t *envp[]);
int spawnvp(int mode, char *path, char *argv[]);
int wspawnvp(int mode, wchar_t *path,
wchar_t *argv[]>;
int spawnvpe (int mode, char *path, char *argv[],
char *envp[]);

446
int

wspawnvpe (int mode, wchar_t *path,


wchar_t *argv [ ] , wchar_t *envp [ ] )

spawn... path, .
exec.... . spawn...
, exec..., mode, . :
P_WAIT

,
.

P_NOWAIT

. ID
, cwait
wait,
. 16- Windows
DOS.

P_NOWAITO

P_NOWAIT, ID ,
cwait wait .

P_DETACH

P_NOWAITO, ,
.

P_OVERLAY

.
, exec....

spawn... , :
L

argO,
argl, ..., argn. , .

argv[]
argO, argl, ..., argn. ,
.

,
PATH. path , , , PATH.
"",
.

env,
. "", .

spawn...
(argO), path. ,
. -

447

( , )
128 .
"1"
. .
NULL, .
"v"
, , .
NULL, , .
"" envp , .

< > = <>

envp = NULL, "" ,


,
.
, , . ,
( ).
, .
path, spawn..., . path , , . ,
, . , . . ,
.com . "" (
path). "" , , PATH.
0 ,
-1.
E2BIG , EINVAL
, ENOENT , ENOEXEC
, ENOMEM .
, cwait wait.

if ( s p a w n l p ( P _ W A I T , " a r j " , " a r j " , "e d o c . a r j a l . t x t " , N U L L ) )


ShowMessage(" arj ");
else
{
Memol->Clear();
Memol->Lines->LoadFromFile("al.txt");
DeleteFile("al.txt");
}

arj, doc.arj al.txt.


, arj ,
Memol .

448

, , . , :
if (spawnlp (P_WAIT, "arj ", " a r j " , "e", " d o c . a r j ", "al . txt",NULL) )

, ,
exec..., . spawn... , P_WAIT,
, . , P_NOWAIT, cwait wait:
int ID = spawnlp (P_ NOWAIT, " a r j " , "ar j " , "e d o c . a r j a l . t x t " , N U L L ) ;
if (ID == -1}
ShowMessage ( " a r j ");
else
{
if (wait (NULL) != ID)
ShowMessage (" ") ;
else
{
Memol->Clear () ;
Memol->Lines->LoadFromFile ("al . txt") ;
DeleteFile ("al .txt") ;

spawnlp P_NOWAIT, . wait, . , , .


,
. , arj,
DOS. DOS,
DOS, ,
. , , . , , arj.bat :
@echo o f f
a r j . e x e e doc %1
exit

exit DOS.
, :
if (spawnlp (P_WAIT, " a r j .bat", " a r j .bat", " a l . t x t " , NULL) )

arj.bat , . , DOS.
spawnlp. , .
. .

449

POverlay.exe. ,
, , OMenage.exe.
. ,
. :
tinclude <vcl.h>
tpragma hdrstop
tinclude <process.h>
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR IpCmdLine, int)
I
spawnlp(P_WAIT,IpCmdLine,IpCmdLine, NULL);
spawnlp(P_OVERLAY,"POverlay.exe","POverlay.exe", NULL);
return 0;

spawnlp
, IpCmdLine.
spawnlp
POverlay.exe.
, POverlay.exe Editl. :
if(spawnlp(P_OVERLAY,"OMenage.exe","OMenage.exe",Editl->Text, NULL))
ShowMessage(" " + Editl->Text + " ;"+
" OMenage.exe");
POverlay.exe
( 10 ) OMenage.exe,
. OMenage.exe ,
POverlay.exe. , POverlay.exe, OMenage.exe.
: POverlay.exe Editl . . POverlay :
tinclude <vcl.h>
tpragma hdrstop
USERES("POverlay.res");
USEFORM("UOverlayl.cpp", Forml);
tinclude "UOverlayl.h" //

it

,
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR IpCmdLine, int)
try
Application->Initialize();
Application->CreateForm( classid(TForml), &Forml);
Forml->Editl->Text = IpCmdLine; // Editl
Application->Run();
catch (Exception &exception)
Application->ShowException (.exception) ;
return 0;

450

, C-H-Builder, ( ): ,
UOverlayl.h, Forml, , Editl , .
,
WinMain IpCmdLine .
POverlay , age :
spawnlp(PJ3VERLAY,"POVERLAY.exe","POVERLAY.exe", IpCmdLine, NULL);

, , , OMenage, POverlay , Editl.

sprintf
.
. . fprintf .

srand
.
. . random .

sscanf
.
. . scanf .

_status87 FPU
FPU.
float.h.

#include < f l o a t . h >


unsigned int _status87(void) ;
unsigned int _ s t a t u s f p ( v o i d ) ;

_status87 _statusfp
FPU (. . 1.9.3). , , . (. . _contro!87, _controlfp FPU, .
_statusfp _status87. Microsoft.
controls?, controlfp
_clear87. _clearfp. , ,
.

float ;
double = 1.5-100;
Labell->Caption = I n t T o H e x ( ( i n t ) _ s t a t u s 8 7 ( ) , 4 ) ;
x = ; //
Label2->Caption = I n t T o H e x ( ( i n t ) s t a t u s 8 7 ( ) , 4) ;

451

,
double , . Labell "0000", Label2 "0030", . , , (. . 1.9.3).
_statusfp FPU
FPU.
. . _status87 FPU.
StdDev
.
Math.hpp.

linclude <Math.hpp>
extern PACKAGE Extended
fastcall
StdDev(const double * Data, const int Data_Size);

StdDev
Data. Data_Size
, . ,

( ) .
, , , .
,
= StdDev(, 9 9 ) ;

100 , .
,
MeanAndStdDev.

. . random
.
StrCopy
.
SysUtils.hpp, string.h, wchar.h, mbstring.h.

extern PACKAGE char *


fastcall
StrCopy (char * Dest, const char * Source);

452

4
extern PACKAGE char *
fastcall
StrECopy(char * Dest, const char * Source);
extern PACKAGE char *
fastcall
StrLCopy(char * Dest, const char * Source,
unsigned MaxLen);
extern PACKAGE char *
fastcall
StrMove(char * Dest, const char * Source,
unsigned Count);
char * strcpy(char *dest, const char *src);
wchar_t * wcscpy(wchar_t *dest, const wchar_t *src);
unsigned char *
_mbscpy(unsigned char *dest, const unsigned char *src);
char * strncpy(char *dest, const char *src, size_t maxlen);
wchar_t *
wcsncpy(wchar t *dest, const wchar_t *src, size_t maxlen);
unsigned char *
_mbsncpy(unsigned char *dest, const unsigned char *src,
size_t maxlen);

Source (src) Dest (dest). :


char b u f f [ 1 0 0 ] ;
. s t r c p y ( b u f f , " , b u f f " ) ;

, StrECopy, . ,
char * = s t r c p y ( b u f f , " , b u f f " ) ;

buff.
StrECopy ,
. . ,
char *S1 = " 1", *S2 = " 2", S[20];
StrECopy(StrECopy(StrECopy(S,SI)," "),S2) ;

S : " 1 2". StrECopy , StrCat.


StrPCopy StrPLCopy
AnsiString .
,
.
StrLen. 1
-,
. , ,
.
, StrLCopy, StrPLCopy, StrMove, strncpy
, MaxLen (Count, maxlen)
. ,
. , MaxLen, MaxLen .
MaxLen 1 , ,
. , Source S

StrLCopy(S,Source, s i z e o f ( S ) - 1 ) ;

Source, , ,
.

453

StrMove ,
.
,
memmove, memcpy , ,
(. . memcpy ).
strcpy
.
. . StrCopy .
StrECopy
.
. . StrCopy .
StrLCopy
.
. . StrCopy .
StrLower
.
. . AnsiLowerCase .
strlwr
.
. . AnsiLowerCase .
StrMove
.
. . StrCopy .
strncpy
.
. . StrCopy .
StrPos

.
. . AnsiPos .
StrToCurr, StrToInt, StrToFloat

, .
SysUtils.hpp.

extern PACKAGE System::Currency


fastcall
StrToCurr(const AnsiString S) ;

454

4
extern PACKAGE System::Currency fastcall
StrToCurrDef(const AnsiString S,
const System::Currency Default);
extern PACKAGE Extended
fastcall
StrToFloat (const AnsiString S) ;
extern PACKAGE Extended
fastcall
StrToFloatDef(const AnsiString S;
const Extended Default);
extern PACKAGE int
extern PACKAGE int
extern PACKAGE bool

fastcall StrToInt(const AnsiString S);


fastcall StrToIntDef(const AnsiString S;
const int Default);
fastcall TryStrToInt (const AnsiString S,
int SValue);

S : StrToCurr
Currency, StrToInt , StrToFloat . ,
EConvertError.
"Def" , Default.
TryStrToInt S Value. , false.

, Editl Edit2. ,
catch:
try

System::Currency = StrToCurr(Editl->Text);
Extended R = StrToFloat(Editl->Text);
int I = StrToInt(Edit2->Text);
}
catch(EConvertError &)
{
//
Application->MessageBox(" ",
" ",
MB_OK+MB_ICONSTOP);
>

int i = StrToIntDef(Editl->Text, 0) ;

i , Editl.
, i .
StrToDate
.
SysUtils.hpp.

tinclude <SysUtils.hpp>
extern PACKAGE S y s t e m : : T D a t e T i m e
fastcall
StrToDate(const AnsiString S ) ;
extern PACKAGE S y s t e m : : T D a t e T i m e
fastcall
StrToDateTime(const A n s i S t r i n g S ) ;
'

455

extern PACKAGE System::TDateTime


fastcall
StrToTime(const AnsiString S);
extern PACKAGE System::TDateTime
fastcall
StrToDateDef(const AnsiString S,
const System::TDateTime Default);
extern PACKAGE System::TDateTime
fastcall
StrToDateTimeDef(const AnsiString S,
const System::TDateTime Default);
extern PACKAGE System::TDateTime
fastcall
StrToTimeDef(const AnsiString S,
const TDateTime Default);

StrToDate StrToDateDef S
TDateTime. StrToTime StrToTimeDef
S , StrToDateTime StrToDateTimeDef
, , .
, "Def" EConvertError, "Def" , Default,
.
, ,
, , DateSeparator ( Windows "."). ShortDateFormat: // , //
Windows, //.
2 , .
, ,
00-99. TwoDigitYearCent Window. TwoDigitYearCentury Window = 0, . , 1999 99 00 1999 1900 , 2000 2099 2000 .
TwoDigitYearCentury Window > 0, , . ,
, - , , , . ,
TwoDigitYearCenturyWindow = 50 1999" , 2000 (
1949 1950) 99 00 1999 2000 .
, , 2 3
, , TimeSeparator ( Windows ":"). , , .
, , .

. , 2002. ,
. "Def" .

1.5.2

StrToDate
01.05.2002

StrToTime

StrToDateTime
01.05.2002

456

StrToDate

StrToTime

StrToDateTime

1.5

01.05.2002

17:5

01.05.2002

17:05:00

17:05:00

17:5:7

17:05:07

17:05:07

1.5.2 17:5

01.05.2002
17:05:00

1.5.0 17:5:7

01.05.2002
17:05:07

StrToDateDef
.
. . StrToDate .
StrToDateTime
.
. . StrToDate .
StrToDateTimeDef
.
. . StrToDate .
StrToTime
.
. . StrToDate .
StrToTimeDef
.
. . StrToDate .
StrUpper
.
. . AnsiUpperCase .
strupr
.
. . AnsiUpperCase .
Sumlnt Sum
.
Math.hpp.

f i n c l u d e <Math.hpp>

457

extern PACKAGE int


fastcall
Sumlnt(const int * Data, const int Data_Size);
extern PACKAGE Extended
fastcall
Sumfconst double *'Data, const int Data_Size);

Sumlnt Sum Data


- . Data_Size
, .
, SumsAndSuuares.

. . random
.
SumOfSquares
.
Math.hpp.

tinclude <Math.hpp>
extern PACKAGE Extended
fastcall
SumOfSquares(const double * Data,

const int Data_Size);

SumOfSquares
Data. Data_Size
, .
, SumsAndSquares.

. . random
.
SumsAndSquares
.
Math.hpp.

tinclude <Math.hpp>
extern PACKAGE void
fastcall
SumsAndSquares(const double * Data, const int Data_Size,
Extended &Sum, Extended SSumOfSquares);

SumsAndSquares Data
Sum SumOfSquares .
Data_Size ,
. SumsAndSquares ,
Sum SumOfSquares. ,
, ,
.

458

. . random
.
swprintf
.
. . fprintf .
swscanf
.
. . scanf .
system
.
process.h.

#include <process.h>
int system(const char *command);
int _wsystem(const wchar_t *command);

system _wsystem command


. command
, DOS
(batch) . , PATH. DOS, Windows . 0
-1 .

// DOS dir
// dir, txt
system("dir dir.txt");
// DOS mkdir, :\\ttt
system("mkdir c:\\ttt");
// Norton Commander
system("nc");

Time
.
. . Date .
TimeToStr
.
. . DateToStr
.
_tmain main
, main.

459

. . main .
Today
.
. . Date .

Tomorrow

.
. . Date .

TotalVariance

.
Math.hpp.

tinclude <Math.hpp>
extern PACKAGE Extended _ fastcall
T o t a l V a r i a n c e (const double * Data, const int Data_Size) ;

TotalVariance
Data :

1=1
, , Variance. PopnVariance. MeanAndStdDev.
Data_Size ,
.

. . random
.
TryEncodeDate

TDateTime _
.
. . EncodeDate TDateTime.
TryEncodeDateTime TDateTime
.
. . EncodeDate TDateTime.
TryEncodeTime

TDateTime _
.
. . EncodeDate TDateTime.
_tWinMain

Windows.
. . WinMain .

460

ungetc
.
. . fgetc / .

ungetch
.
. . fgetc / .

ungetwc
.
. . fgetc / .

UpperCase
.
. . AnsiUpperCase .

va_start, va_arg, va_end


, ,

#include <stdarg.h>
typedef void _FAR *va_list;
void v a _ s t a r t ( v a _ l i s t ap, l a s t f i x ) ;
type va_arg (va__list ap, t y p e ) ;
void va_end(va_list ap) ;

va_start, va_arg va_end , (. . 1, . 1.7.5).


va_start , . lastfix
, .
va_arg . type . va_arg
va_start va_arg. va_arg .
va_end , .
, va_arg .
.

average, Labell . , .
.
:
#include <stdarg.h>
void average(AnsiString mess,...)
{
double A = 0;

461

int i = 0, arg;
va_list ;
va_start (, mess);
while ((arg = va arg (ap, int)) != 0)
f

i++;

A += arg;
}
Forml >Labell->Caption = mess + "N = " +IntToStr(i) +
", = " + FloatToStr (A/i) ;
va_end(ap) ;
}

, , :
average (" : " , 4 , 2 , 3 , 5 , 4 , 0 ) ;

Labell :
: N = 5, = 3 , 6

average ,
( 0), N, :
void average (AnsiString mess, int N, . . . )
{

double A = 0;
va_list ap;
va_start(ap, N) ;

f o r (int i = 0; i < N; i++)

A += va_arg (ap, int) ;


Forml->Labell->Caption = mess + "N = " + I n t T o S t r ( N ) +
", = " + FloatToStr ( A / N ) ;
va_end (ap) ;
}

, , :
average (" : " , 5 , 4 , 2 , 3 , 5 , 4 ) ;

Variance

.
Math.hpp.

#include <Math.hpp>
extern PACKAGE Extended _ fastcall
Variance (const double * Data, const int Data_Size) ;

Variance
Data. Data_Size
, .
,
-

( ) . , , ,
, PopnVariance.
, StdDev MeanAndStdDev. , Sqr(StdDev(A)) = Variance(A).

462

. . random
.
vfprintf
.
. . fprintf .
vfscanf
.
. . scanf .
vfwprintf
.
. . fprintf .
vprintf
.
. . fprintf .
vscanf
( ).
. . scanf .
vsprintf
.
. . fprintf .
vsscanf
.
. . scanf .
vswprintf
.
. . fprintf .
vwprintf
.
. . fprintf .
wait
.
. . cwait .
wcscpy
.
. . StrCopy .

463

wcsncpy
.
. . StrCopy .
__wcslwr
.
. . AnsiLowerCase .
_wcsupr
.
. . AnsiUpperCase .
_wexec...
.
. . exec... .
_wfindfirst
,
.
. . findfirst .
_wfindnext
, _wfindfirst.
. . findfirst .
WinExec API Windows
API Windows, .

UINT W i n E x e c (
LPCSTR IpCmdLine, //
UINT uCmdShow
//
);

WinExec .
IpCmdLine , , , .
, Windows
:
, .
.
. Windows, GetSystemDirectorv.
Windows, GetWindowsDirectory.
PATH.
uCmdShow
Windows. :

464

SW_HIDE

SW_MINIMIZE

() Z-
.

SW MAXIMIZE

() .

SW_RESTORE

.
, (
, SW_SHOWNORMAL).

SW_SHOW

SW_SHOWDEFAULT


SW_ STARTUPINFO,
CreateProcess , .
ShowWindow , .

SW_SHOWMAXIMIZED


().

SW_SHOWMINIMIZED


( ).

SW_SHOWMINNOACTIVE ( ). ,
.
SW_SHOWNA

. , .

SW SHOWNOACTIVATE

. ,
.

SW_SHOWNORMAL

.
, (
, SW_RESTORE).

SW_RESTORE, . , .
Windows, PIF .. .
WinExec , 31. ,
.
WinExec Windows. WIN32, Win32
CreateProcess.

465

Win32 WinExec , GetMessage


. , , , WinExec, GetMessage.

WinExec("file.exe",SW_RESTORE) ;
file.exe.
WinExec("nc",SW_RESTORE);

Norton Commander.
WinExec("COMMAND.COM",SW^RESTORE);

MS-DOS.

int i = W i n E x e c ( E d i t l - > T e x t . c _ s t r ( ) , S W _ R E S T O R E ) ;
if (i < 32)
ShowMessage(" "+ IntToStr ( i ) ) ;

,
Editl.
(char *), AnsiString. c_str().
, .
OpenDialog,

*.;*.com;*.pif;*.dat
*_*

Button ( ), .
OnClick :
if

(OpenDialogl->Execute () )

int i = WinExec ( O p e n D i a l o g l - > F i l e N a m e . c _ s t r ( ) , SW_RESTORE) ;


switch ( i )
{
case 0 : ShowMessage ("He " ) ;
break;
case ERROR_BAD_FORMAT :
ShowMessage (" " + OpenDialogl->FileName) ;
break;
case ERROR_PATH_NOT_FOUND:
ShowMessage ("He " +
ExtractFilePath (OpenDialogl->FileName) ) ;
break;
case ERROR_FILE_NOT__FOUND:
ShowMessage ("He " -t- OpenDialogl->FileName) ;


Windows MS-DOS.

466

WinMain
Windows.
winbase.

int PASCAL WinMain(HINSTANCE hCurlnstance,


HINSTANCE hPrevInstance,
LPSTR IpCmdLine, int nCmdShow)
int PASCAL wWinMain (HINSTANCE hCurlnstance,
HINSTANCE hPrevInstance,
LPWSTR IpCmdLine, int nCmdShow)
int PASCAL _tWinMain (HINSTANCE hCurlnstance,
HINSTANCE hPrevInstance,
LPTSTR IpCmdLine, int nCmd.Show)

WinMain Windows
.
wWinMain Unicode,
Unicode. _tWinMain ,
.
hCurlnstance HINSTANCE . , Windows . API Windows (API Windows Windows, ).
hPrevInstance HINSTANCE
( ).
IpCmdLine LPSTR
, , . WinExec. CreateProcess .
nCmdShow , . ShowWindow.
Win32 , Windows: hPrevInstance NULL, IpCmdLine ,
, . , C++
WinMain, a main.
, WinMain, Windows .
.
WinMain . . 1.2.2.

wmain
C++ Unicode.
. . main .

_wmemcpy
.

.
. . memcpy -

467

_wmemset
.
. . memcpy .
wprintf
.
. . fprintf .
wscanf
( ).
. . scanf .
_wspavn...
.
. . spavn... .
_wsystem
.
. . system .
wWinMain
Windows.
. . WinMain .
YearOf
.
. . DayOf .
YearsBetween
.
DateUtils.hpp.

tinclude <DateUtils.hpp>
extern PACKAGE int
fastcall
YearsBetween(const
const
extern PACKAGE double
fastcall
YearSpan (const
const

System::TDateTime ANow,
System::TDateTime AThen);
System::TDateTime'ANow,
System::TDateTime AThen);

YearsBetween YearSpan ANow AThen TDateTime. YearsBetween


. YearSpan , , .
( ) ,
YearsBetween YearSpan
365.25 . , 01.01 31.12 -

468

YearsBetween 1 , 0 .

TDateTime 11 = EncodeDateTime(2001, 01, 1,


TDateTime 2 = EncodeDateTime(2002, 01, 1,
int i = YearsBetween (T2, Tibdouble r = YearSpan(T2, T l ) ;

00, 00, 00, 3 0 0 ) ;


00, 00, 00, 3 0 0 ) ;

i 1, 1,00205338809035.
1 2 EncodeDateTime 1 . -
YearSpan , , 2000 .
2001 2002 , YearsBetween 0, a YearSpan 0,999315537303217.
YearSpan
.
. . YearsBetween .
Yesterday
.
. . Date .

5

STL
\

5.1 STL?
STL , C++.
, , , ,
, , .
STL : ? , ,
, - . , .
. ,
STL, , . , , , ,
, , , . , ,
, STL ,
. , , STL .
, . , , STL
. , - - . .
.
, STL, C++.
STL , . ,
STL - . ,
STL. .

5.2 STL C++Builder


C++Builder 6 STL STLport 4.5. , STL Rogue
Wave 1998 , American National
Standards Institute (ANSI) International Standards Organization (ISO). Ho no
STLport. Rogue Wave,
#define _USE_OLD_RW_STL.

470

STLport, C++Builder
. ,
.
,
.
#define _STLP_DEBUG.
STL, ,
, , .. (. . 1.8.2). STL std.
STL
using namespace std;

STL. ,
, .
STL,
. ,
using std::swap;

swap STL.
std
. ,
std::swap(x, );

5.3 STL
STL . . 2.14.8 1.7.8.
. , , C++,

. , , , .. .
, STL ,
. , , , .
. , , , , , , sin cos. , .
. , , , ,
. STL
, , .
, STL, ?
, . , . . . .

STL

471

, , : , . ,
. .
, char *. ,
, , . ,
.
allocator, <memory>.
new delete (. . 1.11)
. ,
.
alloc ,
, , .
pthread_alloc,
, . pthread_alloc . , alloc, . ,
, , .
. , , .
, .
, ,
. , , .
- . , , - ,
.
-, , .
. , , .
, ,
. ,
, , .
,
, .
, STL, .

472

5.4
5.4.1
STL : string - - , vector,
valarray bitset (), list , queue deque , stack , set multiset , multimap , hash_set, hash_multiset, hash_map, hash_multimap , , - ( ).
, . , vector, list, deque, map.
. ,
, .
, queue stack deque. : string, valarray, bitset .
, , . . ,
, , , . . 5.4.3.
, . , , .
, , , .
, -
X:

X::value_type

X::iterator
X: :const_iterator
X: reference
X::const_reference




'

X::pointer
X::difference_type


,

X::size_type
,

X::reverse_iterator ,
X: :const_reverse_ , iterator

X::key_type

STL

473

, , X::iterator.
(. . 5.5),
. , II :
v e c t o r < i n t > : : i t e r a t o r II;

- , .
-:

begin

empty
end

/
iterator begin()
const_iterator begin() const
,
bool empty() const
true ( ),
iterator end ()
const_iterator end () const
,

max_size size_type max_size() const


,

size
swap

size_type size() const



void swap(X& x)

begin() , , . end() , . , end(). , , : [ beginQ, end() ).


.
end() begin() . si/e()- max_size() , .
empty() , . ,
, size().
- swap(b)
b . , swap,
( ) , . :
#include <algorithras>
void s w a p ( A s s i g n a b l e S a, Assignables b ) ;

. : ,
, b
.

474

,
swap(a, b ) ;
b .
, b ,
a.swap(b);
b. swap (a) ;
swap (, );

. ,
swap , - swap . - .
-, , , , .
.
(. . 2.14.5).
. , X,
X () ;

b X , b . , ,
X b = ;

X b = X () ;

b = ;

b .

5.4.2
, . ,
.
, . , . 5.4.1, -, .
, .

assign

void assign(lnputlterator first, Inputlterator last)


, , , [first, last]
void assign(size_type n, const T& t)
, , n t

STL

475

back

/
reference back()
const_reference back() const
. *(a.end() - 1)

clear

void clear()

iterator erase(iterator position)
, position. , , ,
end(),

erase

front

insert

iterator erase(iterator first, iterator last)


, [first, last), .. first
last. , ,
, end(),

reference frontQ
const_reference front() const
. *(a.first())
iterator insert(iterator position, const T& x)
, position. ,
void insert(iterator position, size_type n, const T& x)
n ,
position

void insert(iterator position, Inputlterator first, Inputlterator last)


, [first, last],
, position
pop_back void pop_back()
. .se(a.end() - 1)
push_back void push_back(const T& )
. a.insert(a.end(), x)
reverse_iterator rbeginQ
rbegin
const_reverse_iterator rbegin() const
, , .. (
a.end() - 1)

476

rend

resize

/
reverse_iterator rendQ
const_reverse_iterator rend() const
,
, ..
( a.beginQ - 1)
void resize(size_type sz)
sz
void resize(size_type sz, )
sz,

, .. size. clear erase size. erase


,
. , .. . , ,
V, : (1, 2, 3, 4, 5, 6, 7, 8).
II, begin() + 1:
11 = V.begin () + 1;

. :
V.erase(Il) ;

(1, 3, 4, 5, 6, 7, 8).
erase ,
, , erase . , II :
for(int i=l; i <= 5; i++)
V.erase(II) ;

: (1, 7, 8).
(, ),
12,
12 = V.begin () + 6;

V . e r a s e d l , 12);

insert , . , . ,
, .. , . ,
II
V . insert (II, 9);

9 , : (1,
9, 2, 3, 4, 5, 6, 7, 8).
V . i n s e r t ( I I , 3, 9 ) ;

3 9: (1, 9, 9, 9, 2, 3, 4, 5, 6, 7, 8).
insert - . ,
V
V.insertdl, V.end()-2, V . e n d ( J ) ;

STL

477

: (1, 7, 8, 2, 3, 4, 5, 6, 7, 8).
,
.
assign
insert , , , ,
.
V . a s s i g n (3, 9 ) ;
: (9, 9, 9);
resize , sz.
sz > size(), sz - size() .
, .
. , V
V . r e s i z e (10) ;
: (1, 2, 3, 4, 5, 6, 7, 8, , ).
V. resize (10, 9) ;

: (1, 2, 3, 4, 5, 6, 7, 8, 9, 9).
resize sz < size(), .
-, :
/
explicit T(const Allocator& alloc = Allocator())
. (. . 5.3),
explicit T(size_type n)
n , ,
T(size_type n, const T& value, const Allocator& alloc = Allocator())
n , value.

T(lnputlterator first, Inputlterator last, const Allocator& alloc = Allocator())
last first.
, first last, [first,
last), .. last.
, ,
.

5.4.3
,
, , - .
.
.

478

(. . 5.5.4). ,
, . .
:
template <class , class A l l o c a t o r = allocator<T> >
class vector (

vector. . Allocator, . 5.3, , .


, . 5.4.2, -, . 5.4.1 5.4.2. , :
#include <vector>
using namespace std;
vector<int> V;

int size = 0.
5 , 1.
V . insert ( V . begin () , 5, 1 ) ;
:
V . resize (5, 1) ;
:
V . assign (5, 1) ;

, , 1:
vector<int> V ( 5 , 1);

vector<int> V;
for (int i = 1; i <= 10; i+ + )
V.push_back ( i ) ;

1 10.
- . -, .

at

reference at(size_type n)
const_reference at(size_type) const
.
, n [0, size - 1]

capacity

size_type capacity() const


,

reserve

void reserve(size_type n)
capacity,

STL

479

at . 0 size() - 1.
V . a t (0)
,
V . a t ( V . s i z e () - 1) )

.
, out_of_range. , , , . , , II , . :
try

V.at(II - V.begin());
<, 11>

}
catch(out_of_range)
1
ShowMessage(" ");

capacity. , capacity, , . capacity() , size(), . .. , , .


,
, . ,
capacity() size(),
. capacity(),
, , . . STL, C++Builder 6,
.
- . , ( . . 5.5). , .
, capacity(). ,

int old_capacity = V . c a p a c i t y ( ) ;

, , :
if (old capacity != V.capacity ( ) )
(
< >
old_capacity = V . c a p a c i t y ( ) ;
}

capacity .
reserve, , , . , . , ,
1000 ,

480

5
V.reserve(500);

C++Builder 6 ,
capacity 1000, .
reserve,
max_size(), length_error,
-
.

reserve . , - , , . , ,
C++Builder 6 . , , . ,
, -
, ,
reserve, .
. [],
. 0, 1
size(). ,

for (int i=0; i < V . s i z e -1; i++)
ShowMessage(V[i]);

,
, , . . 5.5.1 , , ,
.

. :
int v[10] = {1,2,3,4,5,6,7,8,9,10};
vector<int> V(v,v+10);

, V v, . .
vector. .
.
, , :
, ..
. ,
, ,
, . , -
. ,
, .
,
bool vector<bool>. , , , , ,

STL

481

, ,
. vector<bool>. . , vector<bool>
:

flip

void ()
: true false

swap

void swap(reference x, reference )


flip : , true, false .


, ,
:
vector<bool> V(4);
V[0] = true;
V[l] = false;
V[2] = false;
V[3] = true;
for (int i=0; i < V . s i z e O ; i + + )
V [ i ] ? ShowMessage ("true") : ShowMessage ( " f a l s e " ) ;

: (true, false, false, true).


V .f l i p( ) ;

: (false, true, true, false).


vector<bool> swap, . 5.4.1, , .
vector<bool> . bit_vector,

vector<bool>.

bitset. bitset<N>, bitset,
N, .
, .. bitset . ,
(. . 1.9.7), .
valarray, valarray. , , vector,
, . valarray . , , vector.
10 1 10:
#include <valarray>
valarray<double>
for (int i = 1; i <= 10;
V [ i ] = i;

482

, valarray.
V *= 10;

, 10. , ?
valarray V, VI V2
:
V = 10 * V I ; // V[i] = 10 * VI [i]
V = VI + V 2 ; // V[i] = VI [i] + V2[i]
V = VI * V 2 ; // V[i] = Vl[i] * V2[i]

V VI, 10.
VI V2, V . . .
. V VI V2.
valarray -:
(shift) (cshift) ,
(sum), (min) () , , . (slice) . , , , . , ,
,
.
C++Builder 6 STL .

5.4.4
list. , .
.
. , ,
. 2.12.2 . , . , , (. . 5.5.4). (. 5.5.4),
.
,
.
. , .
list:
template <class , class Allocator = allocator<T> >
class list (

list.
. Allocator, . 5.3,
, .

STL

483

, .
, : Depl
Dep2.
#include <list>
tinclude <string>
using namespace std;
list<string> Depl, Dep2;
Depl .push back ( '") ;
Depl .push back( '") ;
Depl .push back ( '") ;
Dep2 .push back ( '") ;
Dep2 .push back ( '") ;
Dep2 .push back ( '") ;

Depl : ("", "", ""),


Dep2: ("", "", "").
std::string, . 5.6.
list , . 5.4.3
vector, capacity reserve. ,
insert erase. ,
, -:

merge

/
void merge(list<T, Allocator>& x)
, "<",
template<class BinaryPredicate>
void merge(list<T, Allocator>& x, BinaryPredicate comp)
,
comp,

pop_front

void pop_front()

push_front void push_front(const T& )



remove

void remove(const T& value)


, value
template <class Predicate>
void remove_if(Predicate pred)
, pred true

sort

void sort()
"<"
template<class BinaryPredicate>
void sort(BinaryPredicate comp)
comp()

484

splice

/
void splice(iterator position, list<T, Allocator>& x)
position
void splice(iterator position, list<T, Allocator>& x, iterator i)
, i,
position
void splice(iterator position, list<T, Allocator >& x,
iterator first, iterator last)
, [first, last),
position

unique

void unique()
,

template <class BinaryPredicate>
void unique(BinaryPredicate binary_pred)
,
binary_pred

splice
. , .
, position.
. ,
D e p l . s p l i c e ( D e p l . b e g i n ( ) , Dep2);

Dep2 Depl. Depl : ("", "", "", "", "", ""),


Dep2 .
splice , i, position. , [first, last), .
, , , first, , last. , Depl , , :
Depl.splice ( D e p l . b e g i n ( ) , Depl, ++( + +( + + Depl.begin ( ) ) ) , Depl.end ( ) ) ;

: ("", "", "", "",


"", "").
,
Depl.begin() .
, , , . ,

.

STL

485

sort . ,
Depl.sort ;

Depl. Depl , : ("", "", "", "", "").


( ""),
,
. , . .
unique , ,
, . , ,
. ,
. unique Depl
Depl.unique ( ) ;

"".
remove ,
. ,
Depl.remove("");

Depl "".
merge ,
. ,
Depl Dep2,

Depl.merge(Dep2);

, splice sort.
- .
. , find, algorithm :
tinclude <algorithm>
template <class Inputlterator, class T>
Inputlterator f i n d ( I n p u t l t e r a t o r f i r s t ,
const T& v a l u e ) ;

Inputlterator last,

first last ,
: [first, last), .. , first, , last. value
. , ,
last, . , , , Depl Dep2, , . , , :
tinclude <functional>
* f i n d ( D e p l . b e g i n ( ) , Depl.end , "") += " A . A . " ;
* f i n d ( D e p l . b e g i n ( ) , D e p l . e n d ( ) , "") += " . . " ;
"" " ..". find "..".

486

,
, .
:
list<string>::iterator I = find(Depl.begin(), Depl.end(), "");
*I += " A . A . " ;
* f i n d ( I , D e p l . e n d O , "") += " . . " ;

, . , ,
.
:
list<string>::iterator I = D e p l . b e g i n ( ) ;
while ( ( I = f i n d ( I , D e p l . e n d O , "") ) ! = D e p l . e n d O )
*I = "";

Depl.endO,
. ,
.
list. STL,
C-f+Builder 6, slist , . slist list. , . .

5.4.5
, ,
, ,
. . ,
, -
. ,
, .
, .. .
FIFO: . , .
,
. ,
- , .
, ,
.
deque (
). , , .
deque double-ended queue ( ).
deque vector (. . 5.4.2).
, . , , .
deque:
template <class , class A l l o c a t o r = allocator<T> >
class deque;

deque. . Allocator, . 5.3,


, .

STL

487

, .
, Equ:
#include
tinclude <string>
using namespace std;
deque<string> Equ;
f o r ( i n t i=l
Equ. push_back( (" " + IntToStr ( i ) ) . c_str ( ) ) ;

std::string, . 5.6.
deque , -, .
5.4.3 vector, capacity reserve. , . , , s,
, :
s t r i n g s;

- VCL , , :
s = Editl->Text .c_str () ;

FIFO
Equ .push_back(s) ;

if ( ! Equ. empty () )
<
s = Equ. front () ;
Equ . pop_f ront () ;

)
else . . .

,
, , :
if ( ! Equ. empty () )
{
s = Equ. back () ;
Equ . pop_back ( ) ;
}

else . . .

, deque , , insert . (. . 5.4.1) stack () queue (),


. ,
.
stack,
stack, :
# include <stack>
template <class T, class Container>
class stack

488

, , . Container
, .
Container deque . , back(), push_back() pop_back().
,
# include <stack>
tinclude <string>
u s i n g namespace std;

stack<string> St;
deque string.
stack<string, vector<string> > St;

vector string. ">",


"".
, , empty() , , size() , ,
( ):

top

push

pop

/
reference top() { return c.back(); }
const_reference top() const { return c.back(); }
, ,
void push(const value_type& x) { c.push_back(x); }

void pop(){ c.pop_back(); }
() ( )

,
:
string s;
St.push (s);

:
if ( ! S t . e m p t y O ) s = S t . t o p O ;

:
i f ( ! St.emptyO) St.popO;

, .
queue , , , , .
queue,
queue, :
template <class , class Container>
class queue

STL

489

, ,
Container , .
Container deque . , front(), back(),
push_back() pop_back().
,
tinclude <queue>'
tinclude <string>
using namespace std;

queue<string> Que;
deque string.
queue<string, vector<string> > Que;

vector string. ">",


"".
FIFO.
-,
, , . : empty(), size(),
front() , back() , push
(const value_type& x) , () . :
string s;
Que.push ( s ) ;
if ( ! Q u e . e m p t y ( ) ) s = Q u e . b a c k ( ) ;
if ( ! Que.emptyO) s = Que. f r o n t ;
if (! Q u e . e m p t y O ) Que.popO;

//
//
//
//

priority_queue .
vector (
) deque. , queue: empty(),
size(), top() - - , push (const value_type& x) , () .
,
, ().
,
. top.
pop.
.
# include <queue>
using namespace std;
priority_queue<int> PQ;
PQ.push(l);
PQ.push(lO);
PQ.push(S);

.
int i = PQ.top ( ) ;
10 ,
PQ.popO ;
10 , , , 5.

490

- less<T>.
. , PQ
:
priority_queue<int, vector<int>, less<int> >

PQ;

vector<int>,
,
less<int>. . . deque<int>,
. . ,
priority_queue<int, vector<int>, greater<int> > PQ;

, .
.

5.4.6
5.4.6.1

. . .
less<T>, . "<".
set multiset .
multimap
.
(multiset multimap),
(set ).
key_type. value_type ( set multiset ),
.
-, -:

find

iterator find(const key_type& x) const;


,

lower_bound

iterator lower_bound(const key_type& x) const;


, , .
, end()

upper_bound iterator upper_bound(const key_type& x) const;


, , . , end()
count

size_type count(const key_type& x) const;


,

STL

491

,
. ,
find .
5.4.6.2 multiset set
. , , .
less<T>,
. multiset set , set
. . <set>.
, .
tinclude <set>
using namespace std;
multiset<int> MS;
MS.insert (7);
MS.insert (4) ;
MS.insert (4) ;
MS.insert (1) ;
MS.insert(9);
// {1, 4, 4, 7, 9}

int A [ 4 ] = { 6 , 4, 1, 10} ;
set<int> M S I ( A , A + 4 ) ;
/ / { I , 4 , 6 , 10}
m u l t i s e t < i n t , greater<int> > M S 2 ( M S . b e g i n ( ) , M S . e n d O ) ;
// {9, 7, 4, 4, 1}
m u l t i s e t < i n t > MS3;
MS3.insert(MS.begin(), M S . e n d O ) ;
// (1, 4, 4, 7, 9}

MS multiset insert. , , , , .
MS1 set . , , .
, , ,
.
MS2 , MS. less greater.
.
MS3 insert,
, . MS3 MS.
.
true,
. , , MS4 MS, , ,
-

492

. (. - . 5.8). :
struct comp
{
bool operator () (const int II, const int 12) const
{
if ( (II % 2) == (12 % 2) )
return (II < 12) ;
else return (II % 2);

:
multiset<int, comp > MS4 (MS. begin ( ) , MS. end ) ;
, : {1, 7, 9, 4, 4}.
.
:
AnsiString S = "";
multiset<int>: : iterator It;
It = MS. begin () ;
while (It != MS. end ( ) )
S += IntToStr (*It++) + " \ t " ;
ShowMessage (S) ;

It,
S.
, , Editl:
int i = MS. count (StrToInt (Editl-XText) ) )

, "4", i 2,
"5", i 0.
find (. . 5.4.6.1) , , Editl:
if

(MS. f i n d (StrToInt (Editl-XText) )


ShowMessage ("") ;
else ShowMessage ("") ;

==MS.end())

MS . erase (MS . f i n d (4 ) ) ;

, 4. ,
find , .

MS. erase (MS. f i n d (4 ) , MS . end ( ) ) ;

, , 4,
.

ShowMessage (IntToStr (*MS .lower_bound (StrToInt (Editl->Text) ) ) +


" - " + IntToStr ( *MS . upper_bound (StrToInt (Editl-XText) ) ) ) ;

lowerjbound upper_bound (. . 5.4.6.1)


,
, Editl. "7"
"7 - 9", "5" " 7 - 7 " .

STL

493

tinclude <algorithm>
multiset<int> MS4;
insert_iterator<multiset<int> > I t l ( M S 4 , M S 4 . b e g i n ( ) ) ;
set_union (MS. begin () , M S . e n d O , MSI. begin ( ) , M S l . e n d O , I t l ) ;

MS4, Itl ,
set_union (. . 5.7) MS MS1.
, . ,
, , . ,
- , m , max(n, m) . MS4 : {1, 4, 4, 6, 7, 9, 10}.
set_union set_intersection,
: , , , . , -
, m , min(n, m)
. MS4 : {1, 4}.
set_difference,
: , , . " MS4 :
{4, 7, 9}.
, set_symmetric_difference, , , , , .
MS4 : {4, 6, 7, 9, 10}.

if (includes (MS. begin () , MS.endO ,MSI.begin , M S l . e n d O ) )


ShowMessage("");
else ShowMessage("");
, , ( MS), , ( MS1).
multiset set. , set . set insert .
insert . multiset ,
. set insert pair.
.
pair . first second.
insert first ,
( ), second : true,
, false, . pair set:
pair< set<int>::iterator, b6ol> p;
p = MSI.insert(StrToInt(Editi->Text));
if (p.second)

494

ShowMessage(" " + I n t T o S t r ( * p . f i r s t ) ) ;
else ShowMessage(" " + I n t T o S t r ( * p . f i r s t ) +
" ");
, , insert, .

5.4.6.3 multimap
. : .
pair<const Key, Data>. Key , Data . , , , , .
.
, . less<T>,
, "".
multimap ,
. .
<>.
, (),
( ). :
tinclude <map>
using namespace std;
typedef multimap<AnsiString, int> TMM;
TMM MM1;

MM1.insert(TMM::value_type("", 1 9 7 0 ) ) ;
MM1. insert (TMM: : value___type ("", 1980) ) ;
MM1.insert(TMM::value_type("", 1975));
MM1.insert(TMM::value_type("", 1960));
,
multimap<AnsiString, int>.
1 :

1980

1960

1975

1970
, ( )
.
, :
map<AnsiString, int, greater<AnsiString> > 2(1.begin(), M M l . e n d O ) ;
2 map, 1.
greater less. 2
:

STL

495

1970
1975
1980

,
, .
:
AnsiString S = "";
: : iterator It = 1 .begin ();
while (It != MMl.endO)
{
S += (*It). first + " - " + IntToStr( (*It) .second) + "\n";
ShowMessage (S) ;

It .
first second. :
- 1980
- I960
- 1975
1970

( ):
if ( ( I t = 1. f i n d ("" ) ) == M M l . e n d O )
ShowMessage ("" ) ;
else (*It) .second = 1976;

find,
.
multimap . , multiset set.

5.5
5.5.1
. ,
.
, . ,
: istream_iterator ostream_iterator, , . : .
, .
, ,
. , .
STL 6 . (Trivial Iterator)
. (Input Iterator) .

496

'

_
^

5
.

(Output Iterator) , .
, . (Forward
Iterator) , (Bidirectional Iterator)
, (Random Access Iterator)
. : , ? , ,
, , .
, , .
. - begin() , .
- end() , . , ,
: [ begin(), end()). To , end(). end() begin()
.
(*) , .
. , ,
* = ;
,
= *;

.
, .
(++). , .
. . ,
, , . , ,
++;

++;
. ,
, (. . 5.4.3) V, . :
#include <vector>
using namespace std;
vector<int> V;
f o r ( i n t i = 1; i <= 10;
V.push__back ( i ) ;

STL

497

- push_back
V 10 , 1 10.
iterator. . V :
v e c t o r < i n t > : : i t e r a t o r II = V . b e g i n ;
*!!++ = 11;
*I1 = 12;
Labell->Caption = *(++!!);

II , . 11 . 12 (
). II
( ) Labell .
, . , end(). , ,
:
II = V . b e g i n ( ) ;
while (II != V . e n d O )
ShowMessage(*!!++);

. V ,
Num, , , 10.
:
v e c t o r < i n t > : : i t e r a t o r II = f i n d ( V . b e g i n ( ) , V . e n d O , N u m ) ;
if (II != V . e n d O )
{
*I1 *=, 10;
ShowMessage(": " + (AnsiString)(II - V . b e g i n ( ) + 1) +
", :" + * I 1 ) ;
)
else ShowMessage(" ");

II , find. :
#include <algorithm>
template <class Inputlterator, class T>
Inputlterator f i n d ( I n p u t l t e r a t o r f i r s t ,
const T& v a l u e ) ;

Inputlterator last,

first last , value


. , end(), .
iterator. reverse_iterator. , , .
begin() end() rbegin() rend().
rbegin() , a rend() , . 1 .

vector<int>::revers iterator Ir;

498

:
Ir = V . r b e g i n ( ) ;
w h i l e d r != V . r e n d f ) )
ShowMessage(*Ir++);

.
iterator reverse_iterator const_iterator const_reverse_iterator.
, . .
, ,
. ( , , ) distance.
:
template <class Inputlterator>
inline i t e r a t o r _ t r a i t s < l n p u t l t e r a t o r > : : d i f f e r e n c e _ t y p e
distance(Inputlterator first, Inputlterator l a s t ) ;
template <class Inputlterator, class Distance>
void distance ( I n p u t l t e r a t o r f i r s t , Inputlterator last,
Distances n ) ;

first last,
. ,
Labell->Caption = d i s t a n c e ( V . b e g i n ( ) , V . e n d ( ) ) ;
Labell , V.
Label2->Caption = d i s t a n c e ( V . b e g i n ( ) , I I ) ;

Label2 ,
II.
distance STL.
, .
. , ( ,
) n first last.
, , n , .
distance ,
first , last.
.
distance ( ), , first , last. .
. :
Labell->Caption = V . e n d O - V.begin ;
Label2->Caption = II - V.begin ( ) ;

, . , :
int V [ 1 0 ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 1 0 } ;
int * Vbegin = V, * Vend = V + 10;
int * II;

STL

499

,
. Vbegin Vend begin() end().
II , .

:
II = Vbegin;
w h i l e ( I I != Vend)
ShowMessage {'*!!++) ;
Num
10 :
II = find(Vbegin, Vend, Num) ;
i f ( I I != Vend)
(
*I1 *= 10;
ShowMessage(": " + ( A n s i S t r i n g ) ( I I - V . b e g i n ( ) + 1) +
", :" + *I1);
}
else ShowMessage(" ");
, , Vbegin Vend. , ,
, . , , STL ( find). STL .

5.5.2
.
. .
(*), (==) (>) . ,
C++, , (.) . , it , , m it>m, , , (*it).m.
, , ,
. ,
. , ,
. ,
, .
, . - , ..
. , .
istream_iterator. , . ,
cm .

500

. :
istream_iterator(istreami s)
s .
cin . :
istream_iterator()

.
.
,
:
#include<iterator>
#include <iostream>
#include <conio.h>
using namespace std;
int main(void)
{

istream_iterator<int>
int II = *!++;
int 12 = *I;

I (cin);

cout II ' ' 12 endl;


getch() ;
}

main I
. ,
II . 12 ,
getch
- .
. ,
, -. ,
, :
int II = *1;
I++;
int 12 = *1;

, STL .
. :
#include<vector>
#include<iterator>
#include <iostream>
finclude <conio.h>
using namespace std;
int main(void)
{
istream_iterator<int> I (cin);
V.pusHJaack(*!++);
V.push_back(*I);
copy(V.begin(), V.end(), ostream_iterator<int>(cout, " "));
getch () ;
}

:
#include <algorithm>

STL

501

template <class Inputlterator, class Outputlterator>


Outputlterator c o p y ( I n p u t l t e r a t o r f i r s t , Inputlterator last,
Outputlterator r e s u l t ) ;

first last , result .


ostream_iterator,
.
istream_iterator , :
#include<vector>
#include<iterator>
^include <iostream>
tinclude <conio.h>
u s i n g namespace std;
int main(void)
{
c o p y ( i s t r e a m _ i t e r a t o r < i n t > ( c i n ) , istream_iterator<int>() ,
back_inserter(V));
c o p y ( V . b e g i n ( ) , V . e n d O , ostream_iterator<int>(cout, " " ) ) ;
getch() ;
}

.
istream_iterator<mt>(). , . , V
.
Enter,
( Ctrl-Z), - (, ), .
, V, back_inserter. , ( V).
, , ,
, .
, , C++Builder 6 .
- .
, .

5.5.3
. .
, . .
, , . , I
,
*-I = t;

t. ^
, .

502

, . . :
*I = tl;

++I;
*I = t2;

:
*!++ = tl;
*I = t2;

. , , :
*I = tl;
*I = t2;

STL . .
: insert_iterator ,
front__insert_iterator , back_insert_iterator , ostream_iterator
. .
insert_iterator. . :
insert_iterator (Containers , Container :: iterator i)

, , i , .
, , . 1, ,
i, , i . iterator (. . 5.5.1),
.
. V , ,
insert_iterator<vector<int> >
*!!++ = Numl;
*I1 = Num2;

II (V, V . begin () + 3) ;


Numl Num2, ,
2. 2
.
STL, C++Builder 6,
. . , . . , , , - ,
C++Builder, .
, . , , (.
. 5.4.6),
.

STL

503

, , .
front_insert_iterator insert_iterator, . front_insert_iterator . front_insert_iterator
insert_iterator, . insert_iterator, , . , 1 . front_insert_iterator , , .
. , , , ,
front_insert_iterator . list:
#include
tinclude <iterator>
list<int> L;
front_insert_iterator<list<int> > 12 (L) ;
for(int i = 1; i <= 5; i-n-)
*I2++ = i; '
list<int>: : iterator I = L. begin (),
while (I != L.endO )
ShowMessage (*!++) ;

L 12
front_insert_iterator. : 5, 4, 3, 2, 1,
.
back_insert_iterator front_insert_iterator ,
. :
back_insert_iterator<list<int> >

12 (t) ;

: 1, 2, 3, 4, 5.
ostream_iterator. . . :
ostream_iterator (ostreams s)
ostream_iterator (ostreams s, const char* delim)

s . ,
. s . t s t.
delim , .
t s t delim.
,
ostream_iterator<int> lout (cout, " " ) ;
*Iout = Numl;
++Iout;
*Iout = Num2;

Numl
Num2, , .

504

5.5.4 ,
, , ,
: , .
-
, , . , . , , . ,
, .
. , . , , list, list<T>::iterator.

. .
, , "+", "-", "+=", " =", .
,
( > 0) ( < 0). "[]"
, ,
. , : "<", "<=", ">", ">=", .
, i j
X, , :

i +=
i+

n+i
i -= n

( n > 0), ( < 0)


, i +=

i< j

true, i j; , i j

( > 0), ( < 0) ; i += ( )


in
i =
i j, i~J
; , i = j + n
X , , i[n]
; ;
*(i + n)
i[n] = t t X , , ; ;
*(i + n) = t

STL

505

iterator const_
iterator vector deque.
. 5.4. , , "[]" "<". V,
.
, , , . :
vector<int>::iterator II;
for (II = V.begin () + 1; II < V . e n d O - 1; I1++)
ShowMessage(": " + IntToStr(Il - V . b e g i n O + 1) +
", : " +
IntToStr(II[1] - II [-1]));

II V.begin() + 1, ..
. "+".
"<",
"-". , ShowMessage, , II V.beginO. "[]". 11[1] ,
, 11[1] , .

5.6 string
string
, C++ char *. , ,
string,
, char *. , ,
string - , AnsiString,
C++Builder.
string :
typedef basic_string <char>

string;

, string basic_string.
wstring, wchar_t. <string>.
string :
#include <string> .
using namespace std;
string S(" ! " ) ;

string S = " !";

.
string, AnsiString,
. :
string SI (2);
string SI ( '1);

. ,
- :

506

5
s t r i n g S2;
52 = ' ! ' ;

string, char *,
. .
( ) - length.
S S.length() 8.
[ind]. 0. length - 1. , S[0] "", S[7] "!".
[ind] . , , S[8] . at(ind). , [ind], (, S.at(8)) .
() "+",
AnsiString. . ,
S = S1 + ' ' + S2;

S S1 S2, .
"+=". ,
S += S2;

S S2. append:
S.append(32);

"<", ">", "==" .


:
i f ( S I < 32}

.
.
- compare, .
,
SI.compare(S2)

0, S1 S2 , , SI < S2,
, SI > S2.
compare.
.
,
SI.compare(1, 3, S2)

S1 S2. compare . .
, .
compare, . , . ,
SI.compare(0, 4, 52, 1, 4)

S1
S2.

STL

507

substr .
, . ,
S1 = S2.substr(1, 4 ) ;

S1 S2, ( 1)
4 .
swap, . ,
Sl.swap(S2) ;

S1 S2, S2 S1.
insert
. ,
SI.insert(4,S2);

S2 S1. , & , , . insert, ,


, ..
erase , . ,
SI.erase ( 2 , 4 ) ;

S1 4 , 2 (.. ). , , , ,
.
, . find rfind .
. ,
string::npos.
,
string SI = " , . " ;
s t r i n g S2= "";


int i = S l . f i n d ( S 2 ) ;
int j= S l . . r f i n d ( S 2 ) ;

i = 2, j = 26.
, , S
"" "". :
string S2= "", S3 = "";
int i;
if ( (i = S l . f i n d ( S 2 ) ) != s t r i n g : : n p o s )
{
SI.erase(i, S2.length());
S I . i n s e r t (i, S 3 ) ;
}
else ShowMessage(" ");

erase S2, insert


S3.
find
, .
:

508

5
string S2 = "", S3 = "";
int i = 0;
while ( (i = Sl.find(S2, i+1)) != string::nposj
{
SI.erase (i, S2.length ());
SI.insert (i, S3);
}

, (i -I- 1), .. . S2 S3.


find_first_of find_last_of . ,

int i = S l . f i n d _ f i r s t _ o f ( " . ,

:;");

".", ",", " ", ":", ";" S1, ..


. , . , .
, find,
.
find_first_not_of find_last_not _of : ,
.
, erase insert.
replace.
, ,
, . ,
int i = 0;
while ( ( i = S l . f i n d ( S 2 , i+1)) != string::npos)
SI.replace (i, S 2 . l e n g t h ( ) , S 3 ) ;

S2 SI S3.
string.
. , string STL
, . , , string . . ,
API Windows , , char *.
-f+Builder AnsiString.
.
char *
string. :
char * Sen = "";
string S = Sch;

AnsiString
string . - c_str()
AnsiString, AnsiString char *.
string. , string - VCL,
AnsiString, :
string S = ( E d i t l - > T e x t ) . c _ s t r ( ) ;
string SI = (Memol->Text). s t r ( ) ;

STL

509

- c_str() string. char *. char * AnsiString,


string AnsiString. :
s t r i n g S = "";
ShowMessage(S.c_str());
Editl->Text = S . c _ s t r ( ) ;

string char *,
ShowMessage.
Editl>Text, AnsiString.

5.7
5.7.1
STL 100 . , - . ,
STL, . [2]. .
. . 5.8.
,
. , .
, STL. , ,
. ,
. ,
, , .


#include <algorithm>

, ,
: first last. , [first, last), .. ,
, first, , last.
first beginQ, last end(), .
:
( <),
. . , , , , .
, , . . 5.8 - .

.

510

5.7.2

fill

/
template <class Forwardlterator, class T>
void fill(Forward!terator first, Forwardlterator last,
const T& value);
[first, last) value
template <class Outputlterator, class Size, class T>
fill n
void fill_n(OutputIterator first, Size n, const T& value);
n , first,
value
template <class Forwardlterator, class Generator>
generate
void generate(Forward!terator first, Forwardlterator last,
Generator gen);
[first, last) , gen.
, ,
generate_n template <class Outputlterator, class Size, class Generator>
void generate_n(Output!terator first, Size n, Generator gen);
n , first, ,
gen. , ,

5.7.3

/
adjacent_find template <class Forwardlterator> Forwardlterator
Forwardlterator adjacent_find(Forward!terator first,
Forwardlterator last);

count

template <class Forwardlterator, class BinaryPredicate>


Forwardlterator adjacent_find(Forward!terator first,
Forwardlterator last, BinaryPredicate pred);
, ,
. .

pred. [first, last). ,
, , last
template<class Inputlterator, class T>
typename iterator_traits<lnputlterator>::difference_type
count( Inputlterator first, Inputlterator last, const T& value);
template <class Inputlterator, class T, class Size>
void count(lnputlterator first, Inputlterator last,
const T& value, Size& n);
, [first, last)
value. . n

STL

count if

find

find end

find if

511

/
template<class Inputlterator, class Predicate>
typename iterator_traits<lnputlterator>::difference_type
count_if(lnputlterator first, Inputlterator last,
Predicate pred);
template <class Inputlterator, class Predicate, class Size>
void count_if(Inputlterator first, Inputlterator last,
Predicate pred, Size& n);
, [first, last) , pred.
. n
template <class Inputlterator, class T> Inputlterator
Inputlterator find(lnputlterator first, Inputlterator last,
const T& value);
, [first, last), value. , last
template <class Forwardlteratorl, class Forwardlterator2>
Forwardlteratorl find_end(
Forwardlteratorl firstl, Forwardlteratorl last I,
Forwardlterator2 first2, Forwardlterator2 Iast2);
template <class Forward Iteratorl, class Forwardlterator2,
class BinaryPredicate>
Forwardlteratorl find_end(
Forwardlteratorl firstl, Forwardlteratorl lastl,
Forwardlterator2 first2, Forwardlterator2 Iast2,
BinaryPredicate pred);
- [first2, Iast2) [firstl, lastl). , ,
lastl, .
[first2, Iast2) [firstl,
lastl). pred
template <class Inputlterator, class Predicate>
Inputlterator find_if(lnputlterator first, Inputlterator last,
Predicate pred);
, [first, last), ,
pred. , last

512

find first of

search

search n

5
/
template <class Forwardlteratorl, class Forwardlterator2>
Forwardlteratorl find_first_of(
Forwardlteratorl firstl, Forwardlteratorl lastl,
Forwardlterator2 first2, Forwardlterator2 Iast2);
template <class Forward Iteratorl, class Forwardlterator2,
class BinaryPredicate>
Forwardlteratorl find_first_of(
Forwardlteratorl firstl, Forwardlteratorl lastl,
Forwardlterator2 first2, Forwardlterator2 Iast2,
BinaryPredicate pred);
- [first2, Iast2) [firstl, lastl).
, , lastl,
. [first2, Iast2) [firstl, lastl).


template <class Forwardlteratorl, class Forwardlterator2>
Forwardlteratorl search(
Forwardlteratorl firstl, Forwardlteratorl lastl,
Forwardlterator2 first2, Forwardlterator2 Iast2);
template <class Forwardlteratorl, class Forwardlterator2,
class BinaryPredicate>
Forwardlteratorl search (
Forwardlteratorl firstl, Forwardlteratorl lastl,
Forwardlterator2 first2, Forwardlterator2 Iast2,
BinaryPredicate binary_pred);
[first2, Iast2) [firstl, lastl). , , lastl,
. [first2, Iast2)
[firstl, lastl). pred
template <class Forwardlterator, class Size, class T>
Forwardlterator search_n (Forwardlterator first,
Forwardlterator last, Size count, const T& value);
template <class Forwardlterator, class Size, class T,
class BinaryPredicate>
Forwardlterator search_n (Forwardlterator first,
Forwardlterator last, Size count, const T& value,
BinaryPredicate pred);
[first, last) ,
count , value
( ) , , pred value (
). , , lastl,

STL

513

5.7.4

/
binary _search template <class Forwardlterator, class T>
bool binary_search(ForwardIterator first,
Forwardlterator last, const T& value);

equal_range

lower bound

template <class Forwardlterator, class T, class Compare>


bool binary_search(Forward!terator first, Forwardlterator last,
const T& value, Compare comp);
true, [first, last) ,
value ( ) , , - comp value ( )
template <class Forwardlterator, class T>
pair<Forward!terator, Forwardlterator>
equal_range(Forward!terator first, Forwardlterator last,
const T& value);
template <class Forwardlterator, class T, class Compare>
pair<Forward!terator, Forwardlterator>
equal_range(Forward!terator first, Forwardlterator last,
const T& value, Compare comp);
pair [first, last),
,
value, , value.
, ,
value, .
value <.
,
comp
template <class Forwardlterator, class T>
Forwardlterator lower_bound(Forward!terator first,
Forwardlterator last, const T& value);
template <class Forwardlterator, class T, class Compare>
Forwardlterator lower_bound(Forward!terator first,
Forwardlterator last, const T& value,
Compare comp);
[first, last), , value.
, equal_range.
value <.
, comp

514

upper_boimd

template <class Forwardlterator, class T>


Forwardlterator upper_bound(Forward!terator first,
Forwardlterator last, const T& value);
template <class Forwardlterator, class T, class Compare>
Forwardlterator upper_bound(ForwardIterator first,
Forwardlterator last, const T& value,
Compare comp);
[first, last), , value. , equal_range. value
<.
, comp

.
<, ,
. - (. . 5.8)
comp, . , value. , .
lower_bound , equal_range. upper_bound
, equal_range.
, value, .

5.7.5

equal

template <class Inputlteratorl, class Inputlterator2>


boot equal(lnputlteratorl firstl, Inputlteratorl last 1,
Inputlterator2 first2);
template <class Inputlteratorl, class Inputlterator2,
class BinaryPredicate>
bool equal(lnputlteratorl firstl, Inputlteratorl lastl,
Inputlterator2 first2, BinaryPredicate binary_pred);
true, [firstl, lastl)
, first2. , , first2, , [firstl, lastl). ==. nary_pred

STL

515

lexicographical template <class Inputlteratorl, class Inputlterator2>


_compare
bool lexicographical_comparc(
Inputlteratorl first, Inputlterator2 lastl,
Inputlterator2 first2, Inputlterator Iast2);
template <class Inputlteratorl, class Inputlterator2,
class Compare>
bool lexicographical_compare(
Inputlteratorl first, Input Iterator 2 lastl,
Inputlterator2 first2, Inputlterator Iast2,
Compare comp);
true, [firstl, lastl)
[first2, last2).
. true, , , , , . false,
,
, . <. comp
mismatch

template <class Inputlteratorl, class Inputlterator2>


pair<lnputlteratorl,lnputlterator2> mismatch^
Inputlteratorl firstl, Inputlteratorl lastl,
Inputlterator2 first2);
template <class Inputlteratorl, class Inputlterator2,
class BinaryPredicate>
pair<lnputlteratorl, Inputiterator2> mismatch^
Inputlterator firstl, Inputlteratorl lastl,
Inputlterator2 first2,
BinaryPredicate binary_pred);
[firstl, lastl) , first2. , , . ,
.
,
lastl
. ==.

binary_pred

516

5.7.6
/
template <class Inputlterator, class Outputlterator>

Outputlterator copy(lnputlterator first, Inputlterator last,


Outputlterator result);
[firstl, lastl) , result. . .
. ,
result [firstl, lastl).
, first, [firstl, lastl).
,
template <class Bidirectionallteratorl,
_
class Bidirectionallterator2>
backward
Bidirectionallterator2 copy_backward(BidirectionalIteratorl first,
Bidirectionallteratorl last, Bidirectionallterator2 result);
[firstl, lastl) , result. , .. , last - 1. result
. .
.
, result
[firstl, lastl). ,
last,
[firstl, lastl). ,

5.7.7
/
partition template <class Bidirectionallterator, class Predicate>
Bidirectionallterator partition (Bidirectionallterator first,
Bidirectionallterator last, Predicate pred);
[first, last) , , pred, , . , , ..
, pred.
.
stable_partition

STL

random
shuffle "

template <class RandomAccessIterator>


void random_shuffle(RandomAccessIterator first,
RandomAccessIterator last);

517

template <class RandomAccessIterator,


class RandomNumberGeiierator>
void random_shuffle (RandomAccessIterator first,
RandomAccessIterator last,
RandomNumberGenerator& rand);
[first, last),
. - , rand
replace

template <class Forwardlterator, class T>


void replace (Forwardlterator first, Forwardlterator last,
const T& old_value, const T& new_value);
[first, last) ,
old value, new value

replace_
copy

template <class Inputlterator, class Outputlterator, class T>


Outputlterator replace_copy(lnputlterator first, Inputlterator last,
Outputlterator result,
const T& old_value, const T& new_value);
[first, last) ,
result, new_value
, old_value. result-f(last-first), .. ,

!_
copy_if

template <class Inputlterator, class Outputlterator, class Predicate,


class T>
Outputlterator replace_copy_if(lnputlterator first, Inputlterator last,
Outputlterator result, Predicate pred,
const T& new_value);
[first, last) ,
result, new_value
, pred.
result-l-(last-first), .. ,

replace_if

template <class Forwardlterator, class Predicate, class T>


void replace_if(Forward!terator first, Forwardlterator last,
Predicate pred const T& new_value);
[first, last) , pred, new_value

reverse

template <class Bidirectionallterator>


void reverse(Bidirectional!terator first, Bidirectionallterator last);
[first, last)

518

/
reverse,

template <class Bidirectionallterator, class Outputlterator>


Outputlterator reverse_copy (Bidirectionallterator first,
Bidirectionallterator last, Outputlterator result);
[first, last) ,
result,

rotate

template <class Forwardlterator>


void rotate (Forwardlterator first, Forwardlterator middle,
Forwardlterator last);
[first, last) middle - first. , [first, middle), [middle, last). , {1, 2, 3, 4, 5} middle = first + 2 (
3), : {3, 4, 5, 1, 2}.
, middle [first, last)

rotate_
copy

template <class Forwardlterator, class Outputlterator>


Outputlterator rotate_copy (Forwardlterator first,
Forwardlterator middle, Forwardlterator last,
Outputlterator result);
, result,
[middle, last),
[first, middle). [first, last) middle - first . ,
{1, 2, 3, 4, 5} middle = first + 2 ( 3), : {3, 4, 5, 1, 2}. ,
middle [first, last)

stable_
partition

template <class Bidirectionallterator, class Predicate>


Bidirectionallterator stable_partition(Bidirectional!terator first,
Bidirectionallterator last, Predicate pred);
[first, last) ,
, pred, , . , , .. ,
pred. ,
partition

swap

template <class T>


void swap (T& a, T& b);
b

swap_
ranges

template <class Forwardlteratorl, class Forwardlterator2>


Forwardlterator2 swap_ranges (Forwardlteratorl firstl,
Forwardlteratorl lastl, Forwardlterator2 first2);

[firstl, lastl) , first2

STL

519

/
transform template <class Inputlterator, class Outputlterator,
class UnaryOperation>
Outputlterator transform (Inputlterator first, Inputlterator last,
Outputlterator result, UnaryOperation op);
template <class Inputlteratorl, class Inputlterator2,
class Outputlterator, class BinaryOperation>
Outputlterator transform (
Inputlteratorl firstl, Inputlteratorl lastl,
Inputlterator2 first2, Outputlterator result,
BinaryOperation binary_op);
[first, last) (,
, )
, result. result
, .
[firstl, lastl) , first2 binary_op (, )
, result. result ,

5.7.8

/
accumulate template <class Inputlterator, class T>
accumulate (Inputlterator first, Inputlterator last, init);

for each

template <class Inputlterator, class T, class BinaryOperation>


accumulate (Inputlterator first, Inputlterator last, init,
BinaryOperation binary_op);
[first, last) init
. init = 0,
.

init _. , init = 1
multiplies,

template <class Inputlterator, class Function>
void for_each(lnputlterator first, Inputlterator last, Function f);
[first, last)
f .
,
- :
, , ..

520

accumulate :
#include <numeric>

. 5.8.

5.7.9

remove

template <class Forwardlterator, class T>


Forwardlterator remove(Forward!terator first,
Forwardlterator last, const T& value);

[first, last) ,
value. ,
. . . , ,
. ,
: container.erase(remove(first,last,value),container.end());
remove_copy template <class Inputlterator, class Outputlterator, class T>
Outputlterator remove_copy(lnputlterator first,
Inputlterator last, Outputlterator result, const T& value);
result
[first, last), , value. ,
remove_
copy_if

template <class Inputlterator, class Outputlterator,


class Predicate>
Outputlterator remove_copy_if(lnputlterator first,
Inputlterator last, Outputlterator result, Predicate pred);
result
[first, last), , pred.
,

remove if

template <class Forwardlterator, class Predicate>


Forwardlterator remove_if(Forward!terator first,
Forwardlterator last, Predicate pred);
[first, last) ,
pred. , .
. .
, ,
. ,
:
container. erase(remove_if (first, last, pred), container. end());

STL

unique

template <class Forwardlterator>


Forwardlterator unique(ForwardIterator first,
Forwardlterator last);

521

template <class Forwardlterator, class BinaryPredicate>


Forwardlterator unique(Forward!terator first,
Forwardlterator last, BinaryPredicate binary_pred);
[first, last) ,
, ( ) binary_pred ( ), . , . , ,
unique_copy template <class Inputlterator, class Outputlterator>
Outputlterator unique_copy(lnputlterator first,
Inputlterator last, Outputlterator result);
template <class Inputlterator, class Outputlterator,
class BinaryPredicate>
Outputlterator unique_copy(lnputlterator first,
Inputlterator last, Outputlterator result,
BinaryPredicate binary_pred);
[first, last)
result.
, ( - ,
) binary_pred (
), .
, ,

5.7.10

inplace_
merge

template <class Bidirectionallterator>


void inplace_merge(BidirectionalIterator first,
Bidirectionallterator middle,
Bidirectionallterator last);
template <class Bidirectionallterator, class Compare>
void inplace_merge(BidirectionalIterator first,
Bidirectionallterator middle,
Bidirectionallterator last, Compare comp);
[first, middle)
[middle, last) [first, last).
, .
<, comp

522

merge

/
template <class Inputlteratorl, class Inputlterator2,
class Outputlterator>
Outputlterator merge(lnputlterator firstl, Inputlteratorl lastl,
Inputlterator2 first2, Inputlterator Iast2,
Outputlterator result);

template <class Inputlteratorl, class Inputlterator2,


class Outputlterator, class Compare>
Outputlterator merge(lnputlteratorl firstl, Inputlteratorl lastl,
Inputlterator2 first 2, Inputlterator Iast2,
Outputlterator result, Compare comp);
[firstl, lastl)
[first2, Iast2) , result. , .
<, comp
nth element template <class RandomAccessIterator>
void nth_element(RandomAccessIterator first,
RandomAccessIterator nth, RandomAccessIterator last);
template <class RandomAccessIterator, class Compare>
void nth_element (RandomAccessIterator first,
RandomAccessIterator nth, RandomAccessIterator last,
Compare comp);
[first, last) :
,
, nth, , , , nth.
. >, comp
partial_sort template <class RandomAccessIterator>
void parftal_sort(RandomAccess!terator first,
RandomAccessIterator middle,
RandomAccessIterator last);
template <class RandomAccessIterator, class Compare>
void partial_sort(RandomAccess!terator first,
RandomAccessIterator middle,
RandomAccessIterator last,
Compare comp) ;
: middle - first
[first, last). [middle, last) ,
,
. middle = last, . <, comp .

STL

partial_
sort_copy

523

/
template <class Inputlterator, class RandomAccessIterator>
void partial_sort_copy (Inputlterator first, Inputlterator last,
RandomAccessIterator result_first,
RandomAccessIterator result_last);
template <class Inputlterator, class RandomAccessIterator,
class Compare>
void partial_sort_copy (Inputlterator first, Inputlterator last,
RandomAccessIterator result_first,
RandomAccessIterator result_last,
Compare comp);
, : [first, last) ,
, [result_first, result_last), , sult_first. , , ,
: ,
n = min{ last - first, result_last - result_first}. <, comp

sort

stable sort

template <class RandomAccessIterator>


void sort (RandomAccessIterator first,
RandomAccessIterator last);
template <class RandomAccessIterator, class Compare>
void sort (RandomAccessIterator first,
RandomAccessIterator last,
Compare comp);
[first, last).
<
, .
. , stable_sort
template <class RandomAccessIterator>
void stable_sort(RandomAccess!terator first,
RandomAccessIterator last);
template <class RandomAccessIterator, class Compare>
void stable_sort (RandomAccessIterator first,
RandomAccessIterator last, Compare comp);
[first, last).
<, . .
, sort

524

5.7.11
/
template <class Inputlteratorl, class Inputlterator2>
includes
bool includes (Inputlteratorl firstl, Inputlteratorl lastl,
Inputlterator2 first2, Inputlterator2 Iast2);

set_
difference

set_intersection

template <class Inputlteratorl, class Inputlterator2, class Compare>


bool includes (Inputlteratorl firstl, Inputlteratorl lastl,
Inputlterator2 first2, Inputlterator2 Iast2, Compare comp);
true,
[first2, Iast2) [firstl,
lastl). <, comp
template <class Inputlteratorl, class Inputlterator2,
class Outputlterator>
Outputlterator set_difference(lnputlteratorl firstl,
Inputlteratorl lastl, Inputlterator2 first2,
Inputlterator2 Iast2, Outputlterator result);
template <class Inputlteratorl, class Inputlterator2,
class Outputlterator, class Compare>
Outputlterator set_difference (Inputlteratorl firstl,
Inputlteratorl lastl, Inputlterator2 first2,
Inputlterator2 Iast2, Outputlterator result, Compare comp);
, result, [firstl, lastl)
[first2, Iast2). , [firstl,
lastl), [first2, Iast2). , .

<, comp
template <class Inputlteratorl, class Inputlterator2,
class Outputlterator>
Outputlterator set_intersection (Inputlteratorl firstl,
Inputlteratorl lastl, Inputlterator2 first2,
Inputlterator Iast2, Outputlterator result);
template <class Inputlteratorl, class Inputlterator2,
class Outputlterator, class Compare>
Outputlterator set_intersection (Inputlteratorl firstl,
Inputlteratorl lastl, Inputlterator2 first2,
Input] terator2 Iast2, Outputlterator result, Compare comp);
, result, [firstl, lastl)
[first2, Iast2). , [firstl,
lastl), [first2, Iast2),
. ,
.
<, comp

STL

525

/
set_
template <class Inputlteratorl, class Inputlterator2,
symmetric_
class Outputlterator>
difference
Outputlterator set_symmetric_difference (Inputlteratorl firstl,
Inputlteratorl lastl, Inputlterator2 first2,
Inputlterator2 Iast2, Outputlterator result);

set union

template <class Inputlteratorl, class Inputlterator2,


class Outputlterator, class Compare>
Outputlterator set_symmetric_difference (Inputlteratorl firstl,
Inputlteratorl lastl, Inputlterator2 first2,
Inputlterator2 Iast2, Outputlterator result,
Compare comp);
, result, , [firstl,
lastl), [first2, Iast2),
[first2, Iast2), [firstl, lastl). ,
. <,
comp
template <class Inputlteratorl, class Inputlterator2,
class Outputlterator>
Outputlterator set_union (
Inputlteratorl firstl, Inputlteratorl lastl,
Inputlterator2 first2, Inputlterator2 Iast2,
Outputlterator result);
template <class Inputlteratorl, class Inputlterator2,
class Outputlterator, class Compare>
Outputlterator set_union (
Inputlteratorl firstl, Inputlteratorl lastl,
Inputlterator2 t'irst'2, Inputlterator2 Iast2,
Outputlterator result, Compare comp);
[firstl,
lastl) [first2, Iast2). result. <,
. , , , . merge,
.
,
- ,
m , max(n, m)

526

5.7.12 (heap)

/
makc_heap template <class RandomAccessIterator>
void make_heap(RandomAccess!terator first,
RandomAccessIterator last);
template <class RandomAccessIterator, class Compare>
void make_heap(RandomAccessIterator first,
RandomAccessIterator last, Compare comp);
[first, last), . . <,
comp
pop_heap

template <class RandomAccessIterator>


void pop_heap(RandomAccessIterator first,
RandomAccessIterator last);
template <class RandomAccessIterator, class Compare>
void pop_heap(RandomAccess!terator first,
RandomAccessIterator last,
Compare comp);
[first, last)
, last - 1
[first, last - 1). <,
comp

push_heap

template <class RandomAccessIterator>


void pusb_heap(RandomAccess!terator first,
RandomAccessIterator last);
template <class RandomAccessIterator, class Compare>
void push_heap(RandomAccessIterator first,
RandomAccessIterator last,
Compare comp);
, last - 1, ,
[first, last - 1),
[first, last) .
,
, ,
.
<,
comp

STL

sort_heap

template <class RandomAccessIterator>


void sort_heap(RandomAccessIterator first,
RandomAccessIterator last);

527

template <class RandomAccessIterator, class Compare>


void sort_heap(RandomAccessIterator first,
RandomAccessIterator last,
Compare comp);
[first, last), ,
.
<,
comp

(heap) , .
make_heap . pop_heap ( ), ( 1
) . pop_heap , ,
. push_heap
. , , - pop_back.
sort_heap , , .

5.7.13

max

template <class T>


const T& max(const T&, const T&);
template <class T, class Compare>
const T& max(const T&, const T&, Compare);
.
<,

max element template <class Forwardlterator>


Forwardlterator max_element(ForwardIterator first,
Forwardlterator last);
template <class Forwardlterator, class Compare>
Forwardlterator max_element(ForwardIterator first,
Forwardlterator last, Compare comp);
,
[first, last). ,
, . <,

528

mm

template <class T>


const T& min(const T&, const T&);
template <class T, class Compare>
const T& min(const T& a, const T&, Compare);
.
<,

min element

template <class Forwardlterator>


Forwardlterator min_element(ForwardIterator first,
Forwardlterator last);
template <class Forwardlterator, class Compare>
Forwardlterator min_element(ForwardIterator first,
Forwardlterator last, Compare comp);
,
[first, last). ,
, .
<,

5.7.14

next_
permutation

template <class Bidirectionallterator>


bool next_permutation(BidirectionalIterator first,
Bidirectionallterator last);
template <class Bidirectionallterator, class Compare>
bool next_permutation(Bidirectional!terator first,
Bidirectionallterator last, Compare comp);

(. )
[first, last).
, true.
, false. <,
prev_
permutation

template <class Bidirectionallterator>


bool prev_permutation(BidirectionalIterator first,
Bidirectionallterator last);
template <class Bidirectionallterator, class Compare>
bool prev_permutation(BidirectionalIterator first,
Bidirectionallterator last, Compare comp);

(. )
[first, last).
, true.
, false.
<,

STL

529

, , {1 2 3}. , ..
.
: {1 2 3}, {1 3 2}, {2 1 3}, {2 3 1}, {3 1 2}, {3 2 1}. ,
, . next_permutation . ( , .. ), .
prev_permutation, , , .

5.8 -
. 5.7 ,
, - - . STL -.
- , operator ().
,
operator (). - , .
- , - . - :
template <class Arg, class Result>
struct u n a r y _ f u n c t i o n {
typedef Arg argument type;
typedef Result result_type;
};
template <class A r g l , class Arg2, class Result>
struct binary_function {
typedef Argl first_argument_type;
typedef Arg2 second_argument_type;
typedef Result result_type;
};

, :
argument_typ , result_type . : first_argument_type second_argument_type , result_type .
-, . , (
). <functional>.

plus

minus

530

multiplies

divides

modulus

negate

.
. . , - multiplies :
template<class T>
struct m u l t i p l i e s : binary_functiorKT, T, T> {
operator () (const & , const T & ) const;
};

. multiplies accumulate (. . 5.7.8):


#include <numeric>
#include<functional>
u s i n g namespace std;

int a[5] = (1, 2, 3, 4, 5};


int mult = accumulate(a, a+5, 1, multiplies<int>());

accumulate mult
120.

true, ...

equal_to

==

not_equal_to

x!=y

greater

>

less

<

ht greater_equal

>=

less_equal

<=

.
bool.
. , - greater :
template <class T>
struct greater : b i n a r y _ f u n c t i o n < T , T, bool> {
bool o p e r a t o r ( ) (const TS, const T & ) const;

.
greater
sort (. . 5.7.10). less . :

STL

531

tinclude <numeric>
#include<functional>
using namespace std;
int a [ 5 ] = (3, 2, 1, 5, 4 } ;
s o r t ( a , a+5, greater<int> ( ) ) ;

sort greater : {5, 4, 3, 2, 1}.


logical_and

&&

logical_or

||

logical_not

.
bool.
. , - logical_and :
template <class T>
struct logical_and : binary_function<T, T, bool> {
bool operator () (const T&, const T & ) const;
);

.
,
bool ( int).
:
bool 11 [ 4 ] = ( t r u e , f a l s e , f a l s e , t r u e ) ;
bool 1 2 [ 4 ] = { f a l s e , f a l s e , true, t r u e ) ;
t r a n s f o r m ( l l , 11 + 3, 12, 11, logical_and<bool>());

11 12. 6 transform (. . 5.7.7) ,


. 11 {false, false,
false, true}.

-. ,
. . 5.4.6.2. . .
, :
, ,

. ,
.
:
tinclude <math.hpp>
template <class T>
struct mycomp: binary_function<T, T, bool> {
bool o p e r a t o r ! ) (const T& x, const T& y) const

532

if (Sign (x) == Sign () ) return (x < ) ;


else return (x >= 0) ;

. , . true, , .. .

bool . , ,
.

template <class T>
,
struct mycomp: binary_function<T, T, bool>

, - ( mycomp)
bool.
, , . Sign,
math.hpp. . , true,
. , true, .
, , ,
:
int [5] = {3, -10, -2, 5, 4 } ;
double b [ 5 ] = (-4.5, 6, 5.1, 0.5, -10};
sort (a, +5, mycomp<int> () ) ;
sort (b, -5, mycomp<double> () ) ;

b : = {3, 4, 5, -10, -2},


b = {0.5, 5.1, 6, -10, -4.5}.


,
. , .
4,
, . , - .
, ,
.

#
##
#define
#elif
#else
#endif
#error
#if

#ifdef
#ifndef
#include
#line
#pragma
#undef
..

classid
closure
_finally
property
published
_atoi64
_atold
_c_exit
_cexit
_creat
_doserrno
_exception
_exceptionl
_exit
_fdopen
_fileno
_flushall

1.4.5
1.4.5
1.4.2.1, 1.4.2.2
1.4.3
1.4.3
1.4.3
1.4.4
1.4.3
1.4.3
1.4.3
1.4.1
1.4.4
1.4.4
1.4.2.3
1.8.1, 1.8.2,
1.9.13
2.8.3
2.14.7.2
1.12.1
2.14.7.1
2.14.1
3.3.1.1
3.3.1.1
3.6.1
3.6.1
3.5.3
3.1.4.1
3.1.4.4
3.1.4.4
3.6.1
3.5.2
3.5.2
3.5.2

_fsopen
_getdcwd
_getw
_i64toa
_itow
_ltoa
_matherr
_matherrl
_mktemp
_msize
_rmdir
_rtl_chmod
_rtl_close
_rtl_creat
_rtl_open
_sopen
_STLP_DEBUG
_strtold
_sys_errlist
_sys_nerr
_tolower
_toupper
_ui64toa
_ultow
_unlink
_USE_OLD_RW_STL
_waccess
_wcstold
_wrtl_chmod
_wtof
_wtoi
_wtoi64
wtol

3.5.2
3.5.6
3.5.4
3.3.1.1
3.3.1.1
3.3.1.1
3.1.4.4
3.1.4.4
3.5.5
3.7.1
3.5.6
3.5.6
3.5.3
3.5.3
3.5.3
3.5.3
5.2

3.3.1.1
3.1.4.1
3.1.4.1
3.4.1
3.4.1
3.3.1.1
3.3.1.1
3.5.6
5.2

3.5.6
3.3.1.1
3.5.6
3.3.1.1
3.3.1.1
3.3.1.1
3.3.1.1

534
_wtold
access
accumulate
acos
acosl
adjacent_find
AdjustLineBreaks
alloca
allocator
AllocMem
AnsiChar
AnsiExtractQuotedStr
AnsiQuotedStr
AnsiStrLComp
Ansi StrLIComp
AnsiStrRScan
AnsiStrScan
ArcCos
ArcCosh
Arc Sin
ArcSinh
ArcTan2
ArcTanh
ARRAYSIZE
asctime
asin
asinl
assign
at
atan
atan2
atan21
atanl
atexit
atof
atoi
atol
auto
back

3.3.1.1
3.5.6
5.7.8
3.2.3
3.2.3
5.7.3
3.4.2.3
3.7.1
5.3
3.7.1
2.4
3.4.2.3
3.4.2.3
3.4.2.2
3.4.2.2
3.4.2.2
3.4.2.2
3.2.3
3.2.3
3.2.3
3.2.3
3.2.3
3.2.3
2.11.3, 3.7.4
3.3.2
3.2.3
3.2.3
5.4.2
5.4.3
3.2.3
3.2.3
3.2.3
3.2.3
1.12.1, 3.6.1
3.3.1.1
3.3.1.1
3.3.1.1
1.6.2, 1.8.1
5.4.2
back_insert_iterator
5.5.3
back_inserter
5.5.2
Beep
3.7.3
begin
5.4.1
BEGIN_MESSAGE_MAP 1.14.3

C++Builder 6
binary_function
binary_search
bitset
break
bsearch
cabs
cabsl
capacity
catch
ChangeFileExt
char
char*
chdir
chmod
chsize
cin
class
ClassParent
clear
clearerr
close
Close Window
CompareStr
const
const_cast
const_iterator
const_reference
const_reverse_iterator
continue
copy
copyjbackward
cos
Cosh
coshl
cosl
Cotan
count
count_if
cout
CreateDir
creatnew
creattemp
ctime
CurrToFMTBCD

5.8
5.7.4
5.4.3
1.10.2.4
3.7.4
3.2.2
3.2.2
5.4.3
1.12.5, 1.12.6.1
3.5.5
2.4, 2.5.1
2.5.1
3.5.6
3.5.6
3.5.6
1.9.15
1.7.8, 2.14.8
2.8.3
5.4.2
3.5.4
3.5.3
3.7.5
3.4.2.2
1.7.3, 2.14.2
2.2
5.4.1
5.4.1
5.4.1
1.10.2.4
5.7.6
5.7.6
3.2.3
3.2.3
3.2.3
3.2.3
3.2.3
5.4.6.1, 5.7.3
5.7.3
1.9.15
3.5.6
3.5.3
3.5.3
3.3.2
3.3.3


CurrToStrF
CycleToRad
date
DateTimeToFileDate
DateTimeToSystemTime
DateTimeToTimeStamp
DBL_MAX
DBL_MIN
dec
default
DegToRad
delete
DeleteFile
deque
Destroy Window
difference_type
DirectoryExists
DiskFree
DiskSize
distance
divides
DOMAIN
dup
dup2
dynamic_cast
ecvt
EDOM
empty
Enable Window

end
END_MES S AGE_M AP
endl
enum
eof
equal
equal_range
equal_to
ERANGE
erase
errno
Exception
exception

535
3.3.1.2
3.2.3
3.3.2
3.3.2
3.3.2

3.3.2
3.1.4.4
3.1.4.4
2.10.3.2
2.14.7.1
3.2.3
1.11
3.5.6
5.4.5
3.7.5
5.4.1
3.5.6
3.5.6
3.5.6
5.5.1
5.8
3.1.4.4
3.5.3
3.5.3
2.2, 2.14.6
3.3.1.1
3.1.4.3
5.4.1
3.7.5
5.4.1
1.14.3
1.9.15
2.6
3.5.4
5.7.5
5.7.4
5.8
3.1.4.3
5.4.2
3.1.4.1
1.12.4
1.12.7

EXISTINGARRAY
exit

exp
ExpandFileName
ExpandUNCFileName
expl
explicit
extern
ExtractFileDir
ExtractFileDrive
ExtractFileExt
ExtractFileName
ExtractFilePath
ExtractRelativePath
ExtractShortPathName
FA_...
fclose
fcvt
feof
ferror
f flush
fgetpos
FILE
FileAge
FileClose
FileCreate
FileDateToDateTime
FileExists
FileGetAttr
FileGetDate
filelength
FileOpen
FileRead
FileSearch
FileSeek
FileSetAttr
FileSetDate
FileWrite
fill
fill_n
find
find_end
find_first_of

2.11.3, 3.7.4
1.4.4, 1.12.2,
3.6.1
3.2.2
3.5.5
3.5.5
3.2.2
2.14.5
1.6.2, 1.8.1
3.5.5
3.5.5
3.5.5
3.5.5
3.5.5
3.5.5
3.5.5
3.5.1
2.10.2.1, 3.5.2
3.3.1.1
2.10.2.2, 3.5.4
3.5.4
3.5.2
3.5.4
2.10.2.1, 3.5.2
3.5.6
3.5.3
3.5.3
3.5.6
3.5.6
3.5.6
3.5.6
3.5.6
3.5.3
3.5.4
3.5.6
3.5.4
3.5.6
3.5.6
3.5.4
5.7.2
5.7.2
5.4.6.1, 5.7.3
5.7.3
5.7.3

C++Builder 6

536
find_if
flip
FloatToDecimal
FloatToText
FloatToTextFmt
fm...
FMTBCDToCurr
FmtStr
fnmerge
fnsplit
fopen
for_each
ForceDirectories
FormatBuf
FormatCurr
FormatFloat
FPU
fread
freopen
friend
front
front_insert_iterator
fseek
fsetpos
fstat
fstream
ftell
ftime
fwrite
gcvt
generate
generate_n
getcurdir
GetCurrentDir
getcwd
getdate
getdisk
getenv
GetFormatSettings
getftime
GetLongHint
GetMemoryManager
getpass
gets

5.7.3
5.4.3
3.1.3.4, 3.3.1.2
3.1.3.4, 3.3.1.2
3.1.3.5, 3.3.1.2
3.5.1
3.3.3
3.1.3.3, 3.3.1.2
3.5.6
3.5.6
2.10.2.1, 3.5.2
5.7.8
3.5.6
3.1.3.3, 3.3.1.2
3.3.1.2
3.1.3.5, 3.3.1.2
1.9.2, 3.2.6
2.10.2.3, 3.5.4
3.5.2
2.14.2
5.4.2
5.5.3
2.10.2.3, 3.5.4
3.5.4
3.5.6
2.10.3.1
2.10.2.3, 3.5.4
3.5.6
2.10.2.3, 3.5.4
3.3.1.1
5.7.2
5.7.2
3.5.6
3.5.6
3.5.6
3.3.2
3.5.6
3.7.4
3.3.1.2
3.5.6
3.7.4
3.7.1
3.5.4
3.5.4

GetShortHint
GetSystemDirectory
gettime
GetWmdowsDirectory
gmtime
greater
greater_equal
hdrstop
heap
hex
HUGE_VAL
hypot
Hypot
hvDotl
.7
ifstream
includes
IncMonth
InheritsFrom
inline
inplace_merge
insert
insert_iterator
IntToHex
isalnum
isalpha
isascii
isatty
iscntrl
IsDelimiter
isdigit
isgraph
IsLeapYear
islower
IsPathDelimiter
isprint
ispunct
isspace
istream_iterator
isupper
,
iswalnum
iswalpha
iswascii
iswcntrl
iswdigit

3.7.4
3.5.6
3.3.2
3.5.6
3.3.2
5.8
5.8
1.4.4
1.11, 5.7.12
2.10.3.2
3.3.1.1
3.2.3
3.2.3
3.2.3
1.9.15, 2.10.3.1
5.7.11
3.3.2
2.8.3
1.7.6, 2.14.2
5.7.10
5.4.2
5.5.3
3.3.1.2
3.4.1
3.4.1
3.4.1
3.5.6
3.4.1
3.4.2.3
3.4.1
3.4.1
3.3.2
3.4.1
3.4.2.3
3.4.1
3.4.1
3.4.1
5.5.2
3.4.1
3.4.1
3.4.1
3.4.1
3.4.1
3.4.1

537


iswgraph
iswlower
iswprint
iswpunct
iswspace
iswupper
iswxdigit
isxdigit
iterator
itoa
kbhit
key_type
LastDelimiter
LDBL_MAX
LDBL_MIN
less
less_equal
lexicographical_
compare
Wind
LHUGE_VAL
LineStart
list
localtime
lock
locking
logic_error
logical_and
logical_not
logical_or
LoginDialog
LoginDialogEx
lower_bound
IP
LParamHi
LParamLo
Isearch
Iseek
make_heap
manifest
map

MatchesMask
max

3.4.1
3.4.1
3.4.1
3.4.1
3.4.1
3.4.1
3.4.1
3.4.1
5.4.1
3.3.1.1
3.5.4
5.4.1
3.4.2.3
3.1.4.4
3.1.4.4
5.8
5.8

5.7.5
3.7.4
3.3.1.1
3.4.2.2
5.4.4
3.3.2
3.5.3
3.5.3
1.12.7
5.8
5.8
5.8

3.7.2
3.7.2
5.4.6.1, 5.7.4
1.14.1
1.14.1
1.14.1
3.7.4
2.10.2.4, 3.5.4
5.7.12
1.5.3
5.4.6.1, 5.4.6.2,
5.4.6.3
3.5.5
3.2.2, 5.7.13

max_element
max_size
memchr
memcmp
memicmp
merge
message
Message
MES S AGE_HANDLER
MessageBeep
min

min_element
MinimizeName
minus
mismatch
mkdir
mktime
modf
modfl
modulus
MSecsToTimeStamp
multimap
multiplies
multiset
namespace
negate
new

next_permutation
not_equal_to
nth_element
NULL
O_...
oct

ofstream
OPEN ARRAY
ostream_iterator
OVERFLOW
package
ParamCount
ParamStr
partial_sort
partial_sort_copy
partition

5.7.13
5.4.1
3.4.2.1
3.4.2.1
3.4.2.1
5.4.4, 5.7.10
1.4.4
1.12.4.1
1.14.3
3.7.3
3.2.2, 5.7.13
5.7.13
3.5.5
5.8

5.7.5
3.5.6
3.3.2
3.2.2
3.2.2
5.8

3.3.2
5.4.6.1, 5.4.6.3
5.8

5.4.6.1, 5.4.6.2
1.8.2
5.8

1.11
5.7.14
5.8

5.7.10
2.8.2
3.5.1
2.10.3.2
1.9.15, 2.10.3.1
1.12.4.2,
2.11.3, 3.7.4
5.5.3
3.1.4.4
1.4.4
3.7.4
3.7.4
5.7.10
5.7.10
5.7.7

538

PlaySound
plus
pointer
pop

pop_back
pop_front
pop_heap
precision
prev_permutation
priority_queue
private
ProcessPath
protected
pthread_alloc
public
push
push_back
push_front
push_heap
putch
putenv
puttext
putw
qsort
queue
QuotedStr
RadToCycle
RadToDeg
random_shuffle
rbegin
read
reference
register
reinterpret_cast
remove
remove_copy
rem ove_copy_if
remove_if
RemoveDir
rename
RenameFile
rend

C++Builder 6

3.5.4
3.7.3
5.8

5.4.1
5.4.5
5.4.2
5.4.4
5.7.12
2.10.3.2
5.7.14
5.4.5
2.12.3, 2.14.1
3.5.5
2.14.1
5.3

2.12.3, 2.14.1
5.4.5
5.4.2
5.4.4
5.7.12
3.5.4
3.7.4
3.5.4
3.5.4
3.7.4
5.4.5
3.4.2.3
3.2.3
3.2.3
5.7.7
5.4.2
2.14.7.1, 3.5.4
5.4.1
1.6.2
2.2

3.5.6, 5.4.4,
5.7.9
5.7.9
5.7.9
5.7.9
3.5.6
3.5.6
3.5.6
5.4.2

replace
replace_copy
replace_copy_if
replace_if
reserve
resetiosflags
resize
resource
Result
ResultHi
ResultLo
return
reverse
reverse_copy
reverse_iterator
rotate
rotate_copy
runtime_error
S_...
search
search_n
searchpath
Sender

5.7.7
5.7.7
5.7.7
5.7.7
5.4.3
2.10.3.3
5.4.2
1.4.4
1.14.1
1.14.1
1.14.1
1.7.1, 1.10.2.4
5.7.7
5.7.7
5.4.1
5.7.7
5.7.7
1.12.7
3.5.1
5.7.3
5.7.3
3.5.6
2.8.3

Set
set

2.7

set_difference
set_intersection
set_symmetric_difference
set_terminate
set_unexpected
set_union
setbase
setbuf
SetCurrentDir
setdate
setdisk
setfill
setftime
setiosflags
setmem
SetMemory Manager
setmode
setprecision
set time

5.4.6.1, 5.4.6.2
5.7.11
5.7.11
5.7.11
1.12.7
1.12.7
5.7.11
2.10.3.2
3.5.2
3.5.6
3.3.2
3.5.6
2.10.3.2
3.5.6
2.10.3.3
3.4.2.1
3.7.1
3.5.3
2.10.3.2
3.3.2

539

setvbuf
setw
SH_...
Shortcut
ShortCutToText
ShowException
sin
SinCos
SING
Sinh
sinh
sinhl
sinl
size
size_type
sizeof
slist
sort
sort_heap
splice
sqrt
sqrtl
stable_partition
stable_sort
stack
startup
stat
static
static_cast
stime
StrAlloc
StrBufSize
strcat
StrCat
strchr
strcmp
strcmpi
StrComp
strcspn
strdup
StrEnd
strerror

3.5.2
2.10.3.2
3.5.1
3.7.4
3.7.4
1.12.5.2
3.2.3
3.2.3
3.1.4.4
3.2.3
3.2.3
3.2.3
3.2.3
5.4.1
5.4.1
1.9.10
5.4.4
5.4.4, 5.7.10
5.7.12
5.4.4
3.2.2
3.2.2
5.7.7
5.7.10
5.4.5
1.4.4
3.5.6
1.6.2, 1.7.1,
1.8.1, 2.14.3,
2.14.4
2.2, 2.8.3
3.3.2
3.4.2.2
3.4.2.2
2.5.1, 3.4.2.2
3.4.2.2
3.4.2.2
3.4.2.2
3.4.2.2
3.4.2.2
3.4.2.2
3.4.2.2
3.4.2.2
3.4.2.2

3.1.3.3, 3.3.1.2
3.4.2.2
3.4.2.2
5.6
3.4.2.3
3.4.2.2
3.4.2.2
2.5.1, 3.4.2.2
3.4.2.2
3.1.3.3, 3.3.1.2
3.4.2.2
3.4.2.2
3.4.2.2
3.4.2.2
3.4.2.2
3.4.2.2
3.4.2.2
3.4.2.2
3.4.2.2
3.4.2.2
3.4.2.2
3.4.2.2
3.4.2.2
3.4.2.2
3.4.2.2
3.4.2.2
2.5.1, 3.4.2.2
3.3.1.1
3.4.2.2
3.3.1.1
3.3.1.1
2.12.1, 2.12.3,
2.12.4
3.7.4
swab
5.4.1, 5.4.3,
swap
5.7.7
5.7.7
swap_ranges
3.7.1
SysFreeMem
3.7.1
SysGetMem
3.7.1
SysReallocMem
SystemTimeToDateTime 3.3.2
3.2.3
Tan
3.2.3
tan
3.2.3
Tanh

StrFmt
stricmp
StrlComp
string
StringReplace
StrLCat
StrLComp
strlen
StrLen
StrLFmt
StrLIComp
strncat
strncmp
strncmpi
StrNew
strnicmp
strnset
strpbrk
StrPCopy
StrPLCopy
strrchr
strrev
StrRScan
StrScan
street
strspn
strstr
strtod
strtok
strtol
strtoul
struct

C++Builder 6

540

tanh
tanhl
tanl
tell
template
terminate
text
TextToFloat
TextToShortCut
TFloatFormat
TFloatValue
THeapStatus
this
throw
time
TimeStampToDateTime
TimeS tampToMS ecs
TLOSS
tm

TMemoryManage
tmpfile
tmpnam
toascii
tolower
top

toupper
towlower
towupper
transform
Trim
TrimLeft
TrimRight
try

typedef
typeid
typename
ultoa
umask
unary_f unction
UNDERFLOW
unexpected
unexpected_handler

2.13
union
3.2.3
5.4.4, 5.7.9
unique
3.2.3
5.7.9
unique_copy
3.2.3
3.5.3
2.10.2.4, 3.5.4 unlock
5.4.6.1, 5.7.4
upper bound
1.7.8, 2.14.8
1.8.2
1.12.7
using
5.4.3
1.4.4
valarray
5.4.1
3.1.3.4, 3.3.1.2 value_type
5.4.3
3.7.4
vector
2.14.6
3.1.3.4
virtual
1.7.1, 2.1, 2.8.1
3.1.3.4
void
1.6.2, 2.2, 2.14
volatile
3.7.1
2.14.6
wchar_t
2.4
1.12.4.1,
wcstod
3.3.1.1
1.12.4.2,
wcstol
3.3.1.1
1.12.6.1, 1.12.7
wcstoul
3.3.1.1
3.3.2
what
1.12.7
3.3.2
WideChar
2.4
3.3.2
WM_ACTIVATE
3.1.5
3.1.4.4
WM ACTIVATEAPP
3.1.5
3.3.2
WM_CANCELMODE
3.1.5
3.7.1
WM_CLOSE
3.1.5
3.5.2
WM_GETMINMAXINFO 3.1.5
3.5.5
WM GETTEXT
3.1.5
3.4.1
WM_SETFONT
3.1.5
3.4.1
WM SETTEXT
3.1.5
5.4.5
wParam
1.14.1
3.4.1
WParamffi
1.14.1
3.4.1
WParamLo
1.14.1
3.4.1
WrapText
3.4.2.3
5.7.7
write
2.14.7.1, 3.5.4
3.4.2.3

2.14.6
3.4.2.3
- 1.6.2, 1.8.1
3.4.2.3

1.12.2, 1.12.5

1.6.2, 1.8.1
2.1

1.9.11
1.7.8, 2.14.8
3.3.1.1
3.5.3
5.8

3.1.4.4
1.12.7
1.12.7

2.14.6
1.6.2
1.6.2, 1.8.1
2.14.1, 2.14.3
1.9.2, 2.8.1
1.9.2, 2.8.1
1.6.2
1.1


2.14.5
- 1.6.2, 1.8.1

1.4.1, 1.4.2.1,
1.4.2.2
(- 1.6.2, 1.8.1
)

1.9.1

2.14.6

1.9.15, 2.10.2,
2.10.3

541

-
-

1.8.2
1.7.1
1.8.1, 1.8.2,
1.9.13
1.7.7
1.1

1.6.2, 1.8.1
2.12.1
5.8

2.14.1, 2.14.2

C++
C++Builder 6
C++ C++Builder.
http://delci.hl.ru
www.binom-press.ru.
1. . . C++BuiIder 6 : , 2002
, , ++ilder 6 C++Builder 5 4. C++Builder, - ,
ADO, InterBase Express, dbExpress, - COM,
COM, CORBA, MIDAS,
. ,
, , , , , , .
, , C++Builder, , , , . , , , .. , ,
. , ,
. ,
. ( )
, .
2.

C++Builder
, . C++Builder Help | Customize F1
. , , ,
[1].
,

542

C++Builder 6

, C++Builder, , ,
(,
). , ,
.
: C++ C++Builder,
C++Builder, TeeChart. 3000,
.
STL, , , .
,
C++Builder, ( ),
. , . , , , , .
: http://labl8.ipu.rssi.ru/
help2/. , 3-4 , , .
,

e-mail. , e-mail
- . , .
3. . ., . . . :
, 2002
(, ) . 3 4 . , 500. , C++Builder.
Turbo Turbo C++,
C++Builder, Visual C++. 300 .
4. . ., . . STL C++.
: , 2002
( )
STL, 5
. , , , , .
. C++ ,
C++Builder.
Turbo C++, C++Builder, Visual C++. 300 .

543

. . C++Builder 6. :
, 2003
( , , Delphi 6). ,
C++Builder, , [1] . , C++Builder 6, : ( ,
, ..), C++Builder 6;
C++Builder 6; ;
, .
,
. .
,
.
,
. .
5.

-

C++Builder . .
1. C++
..
.. , ..
26.08.02. 70100/16.
. . .
. . . 44,2. 4000 . 3145.
-, 2002 .
170026, . , ., 12.


- .
614990, . , -131, . , 34.

Вам также может понравиться