Library Reference
Borland® C++
for OS/2®
Version 1.5
Borland may have patents andbr pending patent applications covering subject matter in this document. The furnishing of this document does not give you any license to these patents.
COPYRIGHT © 1987, 1994 by Borland International. All rights reserved. All Borland product names are trademarks or registered trademarks of Borland International, Inc. Other brand and product names are trademarks or registered trademarks of their respective holders.
Borland International, Inc.
100 Borland Way, Scotts Valley, CA 95066-3249 PRINTED IN THE UNITED STATES OF AMERICA
1 EOR0294
9495969798-987654321 H1
Contents
Introduction 1 clock ... 27
Chapter 1 The main function 3 _close ... -... 28
close ... 28
Arguments to main ... 3 closedir ... 28
An example program ... 4 clreol ... 29
Wildcard arguments ... 5 clrscr ... ' ... 29
An example program ... 5
Using -p (Pascal calling conventions) ... 6
The value main returns ... 6
Passing file information to child processes ... 6
Pop-up screens ... 7
Multi-thread programs ... 7
_control87 ... 30
cos, cosl ... 31
cosh, coshl ... 31
country ... 32
cprintf ... 33
cputs ... 33
Chapter 2 Run-time functions 9 Sample function entry ... 9
- abort ... 10
_creat ... 34
creat ... 34
creatnew ... 35
abs ... 11 creattemp ... 36
access ... 11 _crotl, _crotr ... 37
acos, acosl ... 12
alloca ... 13
cscanf ... 37
ctime ... 38
asctime ... 13 cwait ... 38
asin, asinl ... 14
assert ... 15
delline ... 40
difftime ... 40
atan, atanl ... 15
atan2, atan21 ... 16
atexit ... 16
div ... 40
_dos_close ... 41
_dos_creat ... 41
atof, _atold ... 17
atoi ... 18
_dos_creatnew ... 42
_dos_findfirst ... 43
atol ... 18 _dos_findnext ... 44
_atolCl ... 19
_beginthread ... 19
bsearch ... 20
_dos_getdate, _dos_setdate, getdate, setdate ... 45
_dos_getdiskfree ... 46
_dos~etdrive, _dos_setdrive ... 46
cabs, cabsl ... 21
calloc ... 22
_dos_getfileattr, _dos_setfileattr ... 47
_dos_getftime, _dos_setftime ... 48
ceil, ceill ... 22
_c_exit ... 23
_cexit ... 23
cgets ... 23
chdir ... 24
_dos_gettime,_dos_settime ... 49
_dos_open ... 49
_dos_read ... 50
_dos_setdate ... 51
_dos_setdrive ... 51
_chdrive ... 24
_chmod ... 25
chmod ... 25
_dos_setfileattr ... 52
_dos_setftime ... 52
_dos_settime ... 52
chsize ... 26 _dos_write ... 52
_clear87 ... 26
clearerr ... 27
dostounix ... 53
dup ... 53
dup2 ... 54 fwrite ... 84
ecvt ... 54 gcvt ... 84
_end thread ... 55 getc ... 85
eof ...•... 55 getch ... 85
execl, execle, execlp, execlpe, execv, getchar ... 86
execve,execvp,execvpe ... 56 getche ... 86
_exit ... 58 getcurdir . . . 86
exit ... 58 getcwd ... 87
exp, expl ... 59 getdate ... 88
_expand ... 60 _getdcwd ... 88
fabs, fabsl ... 60 getdfree . . . 88
fclose ... 61 getdisk, setdisk ... 89
fcloseall ... 61 _getdrive ... 89
fcvt ... 61 getenv ... 90
fdopen ... 62 getftime, setftime ... 90
feof ... 63 getpass ... 91
ferror ... 63 getpid ... 92
fflush ... 64 gets ... 92
fgetc ... 64 gettext ... 92
fgetchar ... 65 gettextinfo . . . 93
fgetpos ... 65 gettime, settime ... 94
fgets ... 65 getverify ... 94
filelength ... 66 getw ... 95
fileno ... 66 gmtime ... 95
findfirst ... 67 gotoxy ... 96
findnext ... 68 _heapadd ... 97
floor, floorl ... 69 heapcheck ... 97
flushall ... 69 heapcheckfree ... 97
fmod, fmodl ... 70 heapchecknode ... 98
fnmerge ... 70 _heapchk ... 98
fnsplit ... 71 heapfillfree ... 99
fopen ... 72 _heapmin ... 99
_fpreset ... 73 _heapset ... 100
fprintf ... 74 heapwalk ... 100
fputc ... 74 _heapwalk ... 101
fputchar ... 74 highvideo ... 101
fputs ... 75 hypot, hypotl ... 101
fread ... 75 insline ... 102
free ... 76 isalnum ... 102
freopen ... 76 isalpha ... 103
frexp, frexpl ... 77 isascii . . . 103
fscanf ... 77 isatty ... 104
fseek ... 78 iscntrl ... 104
fsetpos ... 79 isdigit ... 105
_fsopen ... 79 is graph ... 105
fstat, stat ... 81 is lower ... 105
ftell ... 82 isprint ... 106
ftime ... 83 ispunct . . . 106
_fullpath ... 83 isspace ... 107
isupper ... 107 poly, polyl ... 139
isxdigit ... 107 _popen ... 139
itoa ... 108 pow, powl ... 140
kbhit ... 108 pow10, pow10l ... 141
labs ... 109 printf ... 141
ldexp,ldexpl ... 109 putc ... 148
ldiv ... 110 . putch ... 148
lfind ... 110 putchar ... 148
localeconv ... 111 putenv ... 149
localtime ... 113 puts ... 149
lock ... 114 puttext ... 150
locking ... 114 putw ... 151
log, logl ... 115 qsort ... 151
log10,loglOl ... 116 raise ... 152
longjmp ... 116 rand ... 153
lowvideo ... 117 random ... 153
_lrotl, _lrotr ... 118 randomize ... 153
lsearch ... 118 _read ... 154
lseek ... 119 read ... 154
Ito a ... 120 readdir ... 155
_makepath ... 120 realloc ... 155
maUoc ... 121 remove ... 156
_matherr, _matherrl ... : .. 122 rename ... 157
max ... 124 rewind ... 157
mblen ... 124 rewinddir ... 158
mbstowcs ... 125 rmdir ... 158
mbtowc ... 125 rmtmp ... 159
memccpy ... 126 _rotl, _rotr ... 159
memchr ... 126 _rtl_chmod ... 159
memcmp ... 127 _rtl_close ... 160
memcpy ... 128 _rtl_creat ... 161
memicmp ... 128 _rtl_heapwalk ... 161
memmove ... 128 _rtl_open ... 162
memset ... 129 _rtl_read ... 163
min ... 129 _rtl_ write ... 164
mkdir ... 130 scanf ... 165
mktemp ... 130 _searchenv ... 172
mktime ... 131 searchpath ... 173
modf, modfl ... 131 _searchstr ... 173
move text ... 132 setbuf ... 174
_msize ... 132 _setcursortype ... 175
normvideo ... 133 setdate ... 175
offsetof ... 133 setdisk .. . . 175
_open ... 134 setjmp ... 175
open ... 134 setlocale ... 176
opendir ... 135 setmode ... 179
_pclose ... 136 settime ... 180
perror ... 136 setvbuf ... 180
_pipe ... 138 setverify ... 181
iii
signal ... 182 strtoul ... 213
sin, sinl ... 185 strupr ... 213
sinh, sinhl ... 185 strxfrm ... 213
sleep ... 186 swab ... 215
sopen ... ' ... 186 system ... 215
spawnl, spawnle, spawnlp, spawnlpe, spawnv, tan, tanl ... '. " ... 216
spawnve, spawnvp, spawnvpe ... 188 tanh, tanhl ... 216
_splitpath ... 191 tell ... 217
sprintf ... 192 tempnam ... 217
sqrt, sqrtl ... 192 textattr ... 218
srand ... 193 textbackground ... 219
sscanf ... 193 textcolor ... 220
stackavail ... 194 textmode ... 222
stat ... 194 time ... 223
_status87 ... 194 tmpfile ... 223
stime ... 195 tmpnam ... 223
stpcpy ... 195 toascii ... 224
strcat ... 196 _tolower ... 224
strchr ... 196 tolower ... 225
strcmp ... 197 _toupper ... 225
strcmpi ... 197 toupper ... 226
strcoll ... 198 _truncate, _ftruncate ... 226
strcpy ... " ... 198 tzset ... 227
strcspn ... 199 ultoa ... 228
_strdate ... 199 umask ... 228
strdup ... 199 ungetc ... 229
_strerror ... 200 ungetch ... 229
strerror ... 200 unixtodos ... 230
strftime ... 201 unlink ... 230
stricmp ... 203 unlock ... 231
strlen ... 203 utime ... 231
strlwr ... 204 va_arg,va_end,va_start ... 232
stmcat ... 204 vfprintf ... 233
stmcmp ... 205 vfscanf ... 234
stmcmpi ... 205 vprintf ... 234
strncpy ... 206 vscanf ... 235
strnicrnp ... 206 vsprintf ... 236
stmset ... 207 vsscanf ... 236
strpbrk ... 207 wait ... 237
strrchr ... 207 wcstombs ... 238
strrev ... 208 wctomb ... 238
strset ... 208 wherex ... 239
strspn ... 209 wherey ... 239
strstr ... 209 window ... 240
_strtime ... 209 _write ... 240
strtod, _strtold ... 210 write ... 240
strtok ... 211
strtol ... 211
_strtold ... 213
Chapter 3 Global variables 243 _argc ... ,' ... 243
_argv ... 243 Public member functions ., ... 265
_ctype ... , ... 243 istream class ... 265
_daylight ... 244 Public constructor ... 265
_environ ... 244 Public member functions ... 265
errno, _doserrno, _sys_errlist, _sys_nerr ... 245 Protected member functions ... 267
_fileinfo ... 247 istream_ withassign class ... 267
_floatconvert ... 247 Public constructor ... 267
_fmode ... 248 Public member functions ., ... 267
_new_handler ... 248 istrstream class ... 267
_osmajor, _osminor, _osversion ... 249 Public constructors ... 268
_threadid ... 249 of stream class ... 268
__ throwExceptionName, __ throw FileName, Public constructors ... 268
__ throw LineN umber ... 250 Public member functions ., ... 269
_timezone ... 250 ostream class ... 269
_tzname ... 250 Public constructor ... 269
_version ... 251 Public member functions ., ... 269
_wscroll ... 251 ostream_ withassign class ... 270
Chapter 4 The C++ iostreams 253 conbuf class ... 253
Public constructor ... 253
Public member functions ... 253
constream class ... 255
Public constructor ... 255
Public member functions ... 255
filebuf class ... 255
Public constructors ... 256
Public data members ... 256
Public member functions ... 256
fstream class ... 257
Public constructors ... 258
Public member functions ... 258
fstreambase class ... 258
Public constructors ... 258
Public member functions ... 259
ifstream class ... 259
Public constructor ... 270
Public member functions ... 270
ostrstream class ... 270
Public constructors ... 270
Public member functions ., ... 271
streambuf class ... 271
Public constructors ... 271
Public member functions ... 272
Protected member functions ... 273
strstreambase class ... 274
Public constructors ... 274
Public member functions ... 274
strstreambuf class ... 274
Public constructors ... 275
Public member functions ., ... 275
strstream class ... 276
Public constructors ... 276
Public member function ... 276
Public constructors ... 259 Chapter 5 Persistent stream classes and Public member functions ... 260 ma~~ 2n ios class ... -" ... 260 The persistent streams class hierarchy ... 277
Public data members ... 260 fpbase class ... 278
Protected data members ... 261 Constructors ... 278
Public constructor ... 262 Public member functions ., ... 278
Protected constructor ... 262 ifpstream class ... 278
Public member functions ... 262 Public constructors ... 279
Protected member functions ... 264 Public member functions ., ... 279
iostream class ... 264 ipstream class ... 279
Public constructor ... 264 Public constructors ... 279
iostream_ withassign class ... 264 Public member functions ., ... 279
Public constructor ... 265 Protected constructors ... 281
v
Protected member functions ... 281
Friends ... 282
ofpstream class ... 282
Public constructors ... 282
Public member functions ... 283
opstream class ... 283
Public constructors and destructor ... 283
Public member functions ... 283
Protected constructors ... 285
Protected member functions ... 285
Friends ... 285
pstream class ... 286
Type definitions ... 286
Public constructors and destructor ... 286
Public member functions ... 286
Operators ... 287
Protected data members ... 287
Protected constructors ... 287
Protected member functions ... 288
TStreamableBase class ... 288
Type definitions ... 288
Public destructor ... 288
Public member functions ... 288
TStreamableClass class ... 289
Public constructor ... 289
Friends ... 290
TStreamer class ... 290
Public member functions ... 290
Protected constructors ... 290
Protected member functions ... 290
__ DELTA macro ... 291
DECLARE_STREAMABLE macro ... 291
DECLARE_STREAMABLE_FROM_BASE macro ... 291
DECLARE_ABSTRACT_STREAMABLE macro ... 292
DECLARE_STREAMER macro ... 292
DECLARE_STREAMER_FROM BASE macro . 292 DECLARE_ABSTRACT _STREAMER macro .. 292
DECLARE_CASTABLE macro ... 293
DECLARE_STREAMABLE_OPS macro ... 293
DECLARE_STREAMABLE_CTOR macro ... 293
IMPLEMENT_STREAMABLE macros ... 293
IMPLEMENT _STREAMABLE CLASS macro . 294 IMPLEMENT_STREAMABLE - CTOR macros . 294 IMPLEMENT_STREAMABLE=POINTER macro ... 294
IMPLEMENT_ CASTABLE_ID macro ... 294
IMPLEMENT_CASTABLE macros ... 294
IMPLEMENT_STREAMER macro ... 295
IMPLEMENT_ABSTRACT_STREAMABLE macros ... 295
IMPLEMENT_STREAMABLE_FROM_BASE macro ... 295
Chapter 6 The C++ container classes 297 Array containers ... 297
TMArrayAsVector template ... 297
Type definitions ... 297
Public constructors ... 298
Public member functions ... 298
Protected member functions ... 300
Operators ... 300
TMArrayAsVectorIterator template ... 301
Public constructors ... 301
Public member functions ... 301
Operators ... 301
TArrayAsVector template ... 302
Public constructors ... 302
TArrayAsVectorIterator template ... 302
Public constructors ... 302
TMIArrayAsVector template ... 302
Type definitions ... 302
Public constructors ... 303
Public member functions ... 303
Protected member functions ... 305
Operators ... 306
TMIArrayAsVectorIterator template ... 306
Public constructors ... 306
Public member functions ... 306
Operators ... 307
TIArrayAsVector template ... 307
Public constructors ... 307
TIArrayAsVectorIterator template ... 307
Public constructors ... 308
TMSArrayAsVector template ... 308
Public constructors ... 308
TMSArrayAsVectorIterator template ... 308
Public constructors ... 308
TSArray template ... 308
TSArrayAsVector template ... 309
Public constructors ... 309
TSArrayAsVectorIterator template ... 309
Public constructors ... 309
TSArrayIterator template ... 309
TISArrayAsVector template ... 309
Public constructors ... 310
TISArrayAsVectorIterator template ... 310
Public constructors ... 310 Public constructors ... 322
TMISArrayAsVector template ... 310 Binary tree containers ... 322
Public constructors ... 310 TBinarySearchTreelmp template ... 322
Association containers ... 310 Public member functions ... 322
TMDDAssociation template ... 310 Protected member functions ... 323
Public constructors ... 311 TBinarySearchTreeIteratorImp template ... 323
Public member functions ... 311 Public constructors ... 324
Operators ... 311 Public member functions ... 324
TDDAssociation template ... 312 Operators ... 324
Public constructors ... 312 TIBinarySearchTreelmp template ... 324
TMDIAssociation template ... 312 Public member functions ... 325
Public constructors ... 312 Protected member functions ... 325
Public member functions ... 313 TIBinarySearchTreeIteratorImp template ... 326
Operators ... 313 Public constructors ... 326
TDIAssociation template ... 313 Public member functions ... 326
Public constructors ... 313 Operators ... 326
TMIDAssociation template ... 314 Dequeue containers ... 327
Protected data members ... 314 TMDequeAsVector template ... 327
Public constructors ... 314 Type definitions ... 327
Public member functions ... 314 Public constructors ... 327
Operators ... 315 Public member functions ... 327
TIDAssociation template .... ; ... 315 Protected data members ... 329
Public constructors ... 315 Protected member functions ... 329
TMIIAssociation template ... 315 TMDequeAsVectorIterator template ... 329
Public constructors ... 316 Public constructors ... 329
Public member functions ... 316 Public member functions ... 329
Operators ... 316 Operators ... 330
TIIAssociation template ... 316 TDequeAsVector template ... 330
Public constructors ... 317 Public constructors ... 330
Bag containers ... 317 TDequeAsVectorIterator template ... 330
TMBagAsVector template ... 317 Public constructors ... 331
Type definitions ... 317 TMIDequeAsVector template ... 331
Public constructors ... 317 Type definitions ... 331
Public member functions ... 318 Public constructors ... 331
TMBagAsVectorIterator template ... 318 Public member functions ... 331
Public constructors ... 319 TMIDequeAsVectorIterator template ... 333
TBagAsVector template ... 319 Public constructors ... 333
Public constructors ... 319 TIDequeAsVector template ... 333
TBagAsVectorIterator template ... 319 Public constructors ... 333
Public constructors ... 319 TIDequeAsVectorIterator template ... 334
TMIBagAsVector template ... 319 Public constructors ... 334
Type definitions ... 320 TMDequeAsDoubleList template ... 334
Public constructors ... 320 Type definitions ... 334
Public member functions ... 320 Public member functions ... 334
TMIBagAs VectorIterator template ... 321 TMDequeAsDoubleListIterator template ... 336
Public constructors ... 321 Public constructors ... 336
TIBagAsVector template ... 322 TDequeAsDoubleList template ... 336
Public constructors ... 322 TDequeAsDoubleListIterator template ... 336
TIBagAsVectorIterator template ... 322 Public constructors ... 336
vii
TMIDequeAsDoubleList template ... 336 Operators ... 349
Type definitions ... 337 TDoubleListImp template ... 349
Public member functions ... 337 Public constructors ... 350
TMIDequeAsDoubleListlterator template ... 338 TDoubleListlteratorImp template ... 350
Public constructors ... 339 Public constructors ... 350
TIDequeAsDoubleList template ... 339 TMSDoubleListImp template ... 350
TIDequeAsDoubleListlterator template ... 339 Protected member functions ... 350
Public constructors ... 339 TMSDoubleListlteratorImp template ... 351
Dictionary containers ... 339 Public constructors ... 351
TMDictionaryAsHashTable template ... 339 TSDoubleListImp template ... 351
Protected data members ... 339 TSDoubleListlteratorImp template ... 351
Public constructors ... 340 Public constructors ... 351
Public member functions ... 340 TMIDoubleListImp template ... 352
TMDictionaryAsHashTablelterator template .. 340 Type definitions . . . 352
Public constructors ... 341 Public member functions ... 352
Public member functions ... 341 Protected member functions ... 353
Operators ... 341 TMIDoubleListlteratorImp template ... 354
TDictionaryAsHashTable template ... 341 Public constructors ... 354
Public constructors ... 342 Public member functions ... 354
TDictionaryAsHashTablelterator template .... 342 Operators ... 354
Public constructors ... 342 TIDoubleListImp template ... 354
TMIDictionaryAsHashTable template ... 342 TIDoubleListlteratorImp template ... 355
Public constructors ... 342 Public constructors ... 355
Public member functions ... 342 TMISDoubleListImp template ... 355
TMIDictionaryAsHashTablelterator template .343 Protected member functions ... 355
Public constructors ... 343 TMISDoubleListlteratorImp template ... 355
Public member functions ... 343 Public constructors ... 355
Operators ... 344 TISDoubleListImp template ... 356
TIDictionaryAsHashTable template ... 344 TISDoubleListlteratorImp template ... 356
Public constructors ... 344 Public constructors ... 356
TIDictionary AsHashTablelterator template ... 344 Hash table containers ... 356
Public constructors ... 345 TMHashTableImp template ... 356
TDictionary template ... 345 Public constructors and destructor ... 356
TDictionarylterator template ... 345 Public member functions ... 357
Public constructors- ... 345 TMHashTablelteratorImp template ... 357
Double list containers ... 345 Public constructors and destructor ... 357
TMDoubleListElement template ... 345 Public member functions ... ',' ... 358
Public data members ... 345 Operators ... 358
Public constructors ... 346 THashTableImp template ... 358
Operators ... 346 Public constructors ... 358
TMDoubleListImp template ... 346 THashTablelteratorImp template ... 359
Type definitions ... 346 Public constructors ... 359
Public constructors ... 347 TMIHashTableImp template ... 359
Public member functions ... 347 Public constructors ... 359
Protected data members ... 348 Public member functions ... 359
Protected member functions ... 348 TMIHashTablelteratorImp template ... 360
TMDoubleListlteratorImp template ... 348 Public constructors ... 360
Public constructors ... 348 Public member functions ... 360
Public inember functions ... 349 Operators ... 360
TIHashTableImp template ... 361 TMQueueAsVectorIterator template ... 372
Public constructors ... 361 Public constructors ... 372
TIHashTableIteratorImp template ... 361 TQueueAsVector template ... 373
Public constructors ... 361 Public constructors ... 373
List containers ... 361 TQueueAsVectorIterator template ... 373
TMListElement template ... 361 Public constructors ... 373
Public data members ... 362 TMIQueueAsVector template ... 373
Public constructors ... 362 Public constructors ... 373
Operators ... 362 Public member functions ... 373
TMListImp template ... 362 TMIQueueAsVectorIterator template ... 374
Type definitions ... 362 Public constructors ... 375
Public constructors ... 363 TIQueueAsVector template ... 375
Public member functions ... 363 Public constructors ... 375
Protected data members ... 364 TIQueueAsVectorIterator template ... 375
Protected member functions ... 364 Public constructors ... 375
TMListIteratorImp template ... 364 TMQueueAsDoubleList template ... 375
Public constructors ... 364 Public member functions ... 376
Public member functions ... 365 TMQueueAsDoubleListIterator template ... 377
Operators ... 365 Public constructors ... 377
TListImp template ... 365 TQueueAsDoubleList template ... 377
TListIteratorImp template ... : ... 365 TQueueAsDoubleListIterator template ... 377
Public constructors ... 366 Public constructors ... 377
TMSListImp template ... 366 TMIQueueAsDoubleList template ... 377
TMSListIteratorImp template ... 366 Public member functions ... 378
Public constructors ... 366 TMIQueueAsDoubleListIterator template .... 379
TSListImp template ... 366 Public constructors ... 379
TSListIteratorImp template ... 366 TIQueueAsDoubleList template ... 379
TMIListImp template ... 367 TIQueueAsDoubleListIterator template ... 379
Type definitions ... 367 Public constructors ... 379
Public member functions ... 367 TQueue template ... 379
Protected member functions ... 368 TQueueIterator template ... 380
TMIListIteratorImp template ... 368 Set containers ... 380
Public constructors ... 368 TMSetAs Vector template ... 380
Public member functions ... 368 Public constructors ... 380
Operators ... 369 Public member functions ... 380
TIListImp template ... 369 TMSetAsVectorIterator template ... 380
TIListIteratorImp template ... 369 Public constructors ... 380
Public constructors ... 369 TSetAsVector template ... 381
TMISListImp template ... 369 Public constructors ... 381
Public member functions ... 370 TSetAsVectorIterator template ... 381
TMISListIteratorImp template ... 370 Public constructors ... 381
Public constructors ... 370 TMISetAsVector template ... 381
TISListImp template ... 370 Public constructors ... 381
TISListIteratorImp template ... 371 Public member functions ... 382
Public constructors ... 371 TMISetAsVectorIterator template ... 382
Queue containers ... 371 Public constructors ... 382
TMQueueAsVector template ... 371 TISetAsVector template ... 382
Public constructors ... 371 Public constructors ... 382
Public member functions ... 371 TISetAsVectorIterator template ... 382
ix
Public constructors ... 383 Operators ... 394
TSet template ... 383 TVectorImp template ... 394
TSetIterator template ... 383 Public constructors ... 395
Stack containers ... 383 TVectorIteratorImp template ... 395
TMStackAsVector template ... 383 Public constructors ... 395
Type definitions ... 383 TMCVectorImp template ... 395
Public constructors ... 383 Public constructors ... 396
Public member functions ... 384 Public member functions ... 396
TMStackAsVectorIterator template ... 385 Protected data members ... 396
Public constructors ... 385 TMCVectorIteratorImp template ... 397
TStackAsVector template ... 385 Public constructors ... 397
Public constructors ... 385 TCVectorImp template ... 397
TStackAsVectorIterator template ... 385 Public constructors ... 397
Public constructors ... 386 TCVectorIteratorImp template ... 398
TMIStackAsVector template ... 386 Public constructors ... 398
Type definitions ... 386 TMSVectorImp template ... 398
Public constructors ... 386 Public constructors ... 398
Public member functions ... 386 TMSVectorIteratorImp template ... 398
TMIStackAsVectorIterator template ... 387 Public constructors ... 399
Public constructors ... 388 TSVectorImp template ... 399
TIStackAsVector template ... 388 Public constructors ... 399
Public constructors ... 388 TSVectorIteratorImp template ... 399
TIStackAsVectorIterator template ... 388 Public constructors ... 400
Public constructors ... 388
TMStackAsList template .... ~ ... 388
TMIVectorImp template ... 400
Type definitions ... 400
TMStackAsListIterator template ... 389 Public constructors ... 400
Public constructors ... 389 Public member functions ... 400
TStackAsListtemplate ... 389 Operators ... 402
TStackAsListIterator template ... 389 TMIVectorIteratorImp template ... 402
Public constructors ... 389 Public constructors ... 402
TMIStackAsListtemplate ... 389 Public member functions ... 402
TMIStackAsListIterator template ... 390 Operators ... 403
Public constructors ... 390 TIVectorImp template ... 403
TIStackAsList template ... 390 Public constructors ... 403
TIStackAsListIterator template ... 390 TIVectorIteratorImp template ... 403
Public constructors ... 390 Public constructors ... 403
TStack template ... 390 TMICVectorImp template ... 404
TStackIterator template ... 391 Public constructors ... 404
Vector containers ... 391 Public member functions ... 404
TMVectorImp template ... 391 Protected member functions ... 404
Type definitions ... 391 TMICVectorIteratorImp template ... 404
Public constructors ... 391 Public constructors ... 405
Public member functions ... 391 TICVectorImp template ... 405
Operators ... 393 Public constructors ... 405
Protected data members ... 393 TICVectorIteratorImp template ... 405
Protected member functions ... 393 Public constructors ... 406
TMVectorIteratorImp template ... 393 TMISVectorImp template ... 406
Public constructors ... 394 Public constructors ... 406
Public member functions ... 394 TMISVectorIteratorImp template ... 406
Public constructors ... 406 Protected member functions ... 434
TISVectorImp template ... 407 Operators ... 434
Public constructors ... 407 TFileStatus structure ... 436
TISVectorIteratorImp template ... 407 TFile class ... 436
Public constructors ... 407 Public data members ... 436
TShouldDelete ... 408 Public constructors ... 437
TShouldDelete class ... 408 Public member functions ... 438
Public data members ... 408 string class ... 439
Public constructors ... 408 Type definitions . . . 439
Public member functions ... 408 Public constructors and destructor ... 440
Protected member functions ... 408 Public member functions ... 441
Chapter 7 The C++ mathematical classes 411 bcd ... 411
Public constructors ... 412
Friend functions ... 413
complex ... 414
Public constructors ... 414
Friend functions ... 414
Protected member functions ... 448
Operators ... 449
Related global operators and functions ... 451
TSubString class ... 452
Public member functions ... 452
Protected member functions ... 453
Operators ... 453
TCriticalSection class ... 454
Chapter 8 Class diagnostic macros 419 Default diagnostic macros ... 420
Extended diagnostic macros ... 421
Macro message output ... 423
Run-time macro control ... 424
Constructors and destructor ... 455
TCriticaISection::Lock class ... 455
Public constructors and destructor ... 455
TMutex class ... 455
Public constructors and destructor ... 456
Chapter 9 Run-time support 425 Operators ... 456
TMutex::Lock class ... 456
Bad_cast class ... 425 Public constructors ... 456
Bad_typeid class ... 425 Public member functions ... 457
set_new _handler function ... 425
set_terminate function ... 426
TSync class ... 457
Protected constructors ... 457
set_unexpected function ... 427
terminate function ... 427
Type_info class ... 428
Protected operators ... 458
TSync::Lock class ... 458
Public constructors and destructor ... 458
Public constructor ... 428 TThread class ... 458
Operators ... 428
Public member functions ... 428
Type definitions . . . 459
Protected constructors and destructor ... 460
unexpected function ... ; ... 429 Public member functions ... 460
xalloc class ... 429 Protected member functions ... 461
Public constructors ... 429
Public member functions ... 429
Protected operators ... 461
TThread::TThreadError class ... 461
xmsg class ... 430
Public constructor ... 430
Type definitions ... 461
Public member functions ... 462
Public member functions ... 430 TTime type definitions ... 462
Chapter 10 C++ utility classes 431 TDate class ... 431
Type definitions ... 431
Public constructors ... 432
Public member functions ... 432
TTime class ... 462
Public constructors ... 463
Public member functions ... 463
Protected member functions ... 464
Protected data members ... 464
Operators ... 465
xi
Appendix A Run-time library cross-reference 467 Interface routines ... 476
The run-time libraries ... 467 International locale API routines ... 476
Reasons to access the run-time library source Manipulation routines ... 476
code ... 469 Math routines ... 477
The Borland C++ header files ... 469 Memory routines ... 478
Library routines by category ... 472 Miscellaneous routines ... 478
C++ prototyped routines ... 472 Obsolete definitions ... 478
Classification routines ... 473 Process control routines ... 479
Conversion routines ... 473 Console I/O routines ... 480
Directory control routines ... 473 Time and date routines ... 480
Diagnostic routines ... 474 Variable argument list routines ... 480
Inline routines ... 474
Input/output routines ... 474 Index 481
Tables
2.1 Locale monetary and numeric settings .... 111 4.1 The functions declared in constrea.h are not
available for PM applications ... 253
A.1 Obsolete global variables ... 478 A.2 Obsolete function names ... 479
xiii
Figures
5.1 Streamable class hierarchy ... 277
Introduction
Introduction
This manual contains definitions of the Borland C++ classes, nonprivate class members, library routines, common variables, and common defined types for windows programming.
If you'~e new to C or C++ programming, or if you're looking for informa- tion on the contents of the Borland C++ manuals, see the introduction in the User's Guide.
Here is a summary of the chapters in this manual:
Chapter 1: The main function discusses arguments to main (including wild- card arguments), provides some example programs, and gives some information on Pascal calling conventions and the value that main returns.
Chapter 2: Run-time functions is an alphabetical reference of all Borland C++ library functions. Each entry gives syntax, portability information, an operative description, and return values for the function, together with a reference list of related functions and examples of how the functions are used.
Chapter 3: Global variables defines and discusses Borland C++'s global variables. You can use these to save yourself a great deal of programming time on commonly needed variables (such as dates, time, error messages, stack size, and so on).
Chapter 4: The C++ iostreams provides a description of the classes that provide support for I/O in C++ programs.
Chapter 5: Persistent stream classes and macros describes the persistent streams classes and macros.
Chapter 6: The C++ container classes is a description of the C++ objects provided by Borland C++ to support data structures and data abstraction.
Chapter 7: The C++ mathematical classes is a description of C++
mathematics using bcd and complex classes.
Chapter 8: Class diagnostic macros describes the classes and macros that support object diagnostics.
Chapter 9: Run-time support describes functions and classes that let you control the way your program executes at run time in case the program runs out of memory or encounters some exception.
Chapter 10: C++ utility classes describes the C++ date, string, and time classes.
Appendix A: Run-time library cross-reference contains an overview of the Borland C++ library routines and header files. The header files are listed alphabetically, and the library routines are grouped according to the tasks they commonly perform.
c
H A p T E R1
The main function
Every C and c++ program must have a main function; where you place it is a matter of preference. Some programmers place main at the beginning of the file, others at the end. Regardless of its location, the following points about main always apply.
Arguments to main
Three parameters (arguments) are passed to main by the Borland C++
startup routine: argc, argv, and env.
tl argc, an integer, is the number of command-line arguments passed to main.
EI argv is an array of pointers to strings (char *[D.
o argv[O] is the name of the program being run, exactly as the user typed it on the command line.
o argv[l] points to the first string typed on the operating system command line after the program name.
o argv[2] points to the second string typed after the program name.
o argv[argc-l] points to the last argument passed to main.
o argv[argc] contains NULL.
a env is also an array of pointers to strings. Each element of env[] holds a string of the form ENWAR=val ue .
• ENVV AR is the name of an environment variable, such as PATH or COMSPEC .
• value is the value to which ENVV AR is set, such as C: \APPS;C: \ TOOLS; (for PATH) or C:\DOS\COMMAND.COM for COMSPEC.
If you declare any of these parameters, you must declare them exactly in the order given: argc, argv, env. For example, the following are all valid
declarations of main's arguments:
Chapter 1, The main function 3
Refer to the environ entry in Chapter 3 and the putenv and
getenv entries in Chapter 2 for more information.
An example program
int main ()
int main(int argc) 1* legal but very unlikely *1 int main(int argc, char * argv[])
int main(int argc, char * argv[], char * env[])]
The declaration int main (int argc) is legal, but it's very unlikely that you would use argc in your program without also using the elements of argv.
The argument env is also available through the global variable environ.
argc and argv are also available via the global variables _argc and _argv.
Here is an example that demonstrates a simple way of using these arguments passed to main:
1* Program ARGS.C *1
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[], char *env[]) { int i;
printf("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; itt)
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; itt)
printf(" env[%d]: %s\n", i, env[i]);
return 0;
}
Suppose you run ARGS.EXE at the OS/2 prompt with the following command line:
C:> args first_arg "arg with blanks" 3 4 "last but one" stop!
Note that you can pass arguments with embedded blanks by surrounding them with quotes, as shown by "argument with blanks" and "last but one"
in this example command line.
The output of ARGS.EXE (assuming that the environment variables are set as shown here) would then be like this:
The value of argc is 7
These are the 7 command-line arguments passed to main:
argv[O]: args argv[l]: first_arg
Wildcard arguments
'An example program
argv[2]: args with blanks argv [3]: 3
argv[ 4] :
argv[S]: last but one argv[6]: stop!
The environment string(s) on this system are:
env[O]: USER_INI=C:\OS2\OS2.INI env[1]: SYSTEM_INI=C:\OS2\OS2SYS.INI env[2]: OS2_SHELL=C:\OS2\CMD.EXE
env[3]: AUTOSTART=PROGRAMS,TASKLIST,FOLDERS env[4]: RUNWORKPLACE=C:\OS2\PMSHELL.EXE env[5]: COMSPEC=C:\OS2\CMD.EXE
env[6]: PATH=C:\OS2;C:\OS2\SYSTEM;C:\;C:\OS2\APPS;
env[7]: DPATH=C:\OS2;C:\OS2\SYSTEM;C:\;C:\OS2\APPS;
env[8]: PROMPT=$i[$p]
env[9]: HELP=C:\OS2\HELP;C:\OS2\HELP\TUTORIAL;
env [10]: GLOSSARY.=C: \OS2 \HELP\GLOSS;
env[11]: KEYS=ON
env[12]: BOOKSHELF=C:\OS2\BOOK;
env[13]: EPATH=C:\OS2\APPS
Command-line arguments containing wildcard characters can be expanded to all the matching file names, much the same way DOS expands wildcards when used with commands like COPY. All you have to do to get wildcard expansion is to link your program with the WILDARGS.OBJ object file, which is included with Borland C++.
Once WILDARGS.OBJ is linked into your program code, you can send wildcard arguments of the type *.* to your main function. The argument will be expanded (in the argv array) to all files matching the wildcard mask.
The maximum size of the argv array varies, depending on the amount of memory available in your heap.
If no matching files are found, the argument is passed unchanged. (That is, a string consisting of the wildcard mask is passed to main.)
Arguments enclosed in quotes (" ... ") are not expanded.
The following commands compile the file ARGS.C and link it with the wildcard expansion module WILDARGS.OBJ, then run the resulting executable file ARGS.EXE:
BCC ARGS.C WILDARGS.OBJ
ARGS C:\BORLANDC\INCLUDE\*.H "*.C"
When you run ARGS.EXE, the first argument is expanded to the names of all the *.H files in your Borland C++ INCLUDE directory. Note that the
Chapter 1, The main function 5
For more on TUB, see the Users Guide.
expanded argument strings include the entire path. The argument *.C is not expanded because it is enclosed in quotes.
In the IDE, simply specify a project file (from the project menu) that contains the following lines:
ARGS WILDARGS.OBJ
Then use the Run I Arguments option to set the command-line parameters.
If you prefer the wildcard expansion to be the default, modify your
standard C?LIB library files to have WILDARGS.OBJ linked automatically.
To accomplish that, remove SETARGV and INITARGS from the libraries and add WILDARGS. The following commands invoke the Turbo librarian (TLIB) to modify all the standard library files (assuming the current directory contains the standard C and c++ libraries and WILDARGS.OBJ):
tlib c2 -setargv -initargs +wildargs tlib c2mt -setargv -initargs +wildargs
Using -p (Pascal calling conventions)
If you compile your program using Pascal calling conventions (described in detail in Chapter 2, "Language structure," in the Programmer's Guide), you must remember to explicitly declare main as a C type. Do this with the _ _ cdecl keyword, like this:
int __ cdecl main(int argc, chart argv[], chart envp[])
The value main returns
The value returned by main is the status code of the program: an int. If, however, your program uses the routine exit (or _exit) to terminate, the value returned by main is the argument passed to the call to exit (or to _exit).
For example, if your program contains the call exit (1) the status is 1.
Passing file information to child processes
If your program uses the exec or spawn functions to create a new process, the new process will normally inherit all of the open file handles created by
the original process. However, some information about these handles will be lost, including the access mode used to open the file. For example, if your program opens a file for read-only access in binary mode, and then spawns a child process, the child process might corrupt the file by writing to it, or by reading from it in text mode.
To allow child processes to inherit such information about open files, you must link your program with the object file FILEINFO.OBJ. For example:
bee test.c \borlande\lib\fileinfo.obj
The file information is passed in the environment variable _C_FILE_INFO.
This variable contains encoded binary information, and your program should not attempt to read or modify its value. The child program must have been built with the C++ run-time library to inherit this information correctly. Other programs can ignore _C_FILE_INFO, and will not inherit file information.
Pop-up screens
POPUP.OBJ adds about 800 bytes of code to your program.
When the run-time library encounters an unrecoverable error, or your program uses the assert macro with a false condition, the library displays an error message to the standard error file (normally the display screen) and terminates the program. However, if your program uses a windowing system such as Presentation Manager, or redirects standard error, these error messages might be invisible or overwrite existing screen displays.
You can cause error messages to be displayed in a pop-up screen by including the object file POPUP.OB} when you link your program. For example: bee test.c \borlandelib\popup.obj
Multi-thread programs
See the online Help example for _beginthread to see how to use these functions and _threadidin a
program.
OS/2 programs can create more than one thread of execution. OS/2 provides a DosCreateThread function for this purpose. However, the C++
run-time library C2.LIB does not support more than one thread. If your program creates multiple threads, and these threads also use the C++ run- time library, you must use the C2MT. LIB library instead.
The C2MT.LIB library provides the function _begin thread function, which you use to create threads. C2MT.LIB also provides the function _endthread, which terminates threads, and a global variable _threadid. This global variable points to a long integer that contains the current thread's identification number (also known as the thread ID). The header file stddef.h contains the declaration of _threadid.
Chapter 1, The main function 7
When you compile or link a program that uses multiple threads, you must use the -sm compiler switch. For example:
bee -sm thread.e
Special care must be taken when using the signal function in a multi-thread program. See the description of the signal function for more information.
See "The run-time libraries" section in Appendix A for information about linking to the DLL version of the run-time library.
Programming examples for each function are available in the online Help system. You can easily copy them from Help and paste them into your files.
c
H A p T E R2
Run-time functions
This chapter contains a detailed description of each function in the Borland C++ library. The functions are listed in alphabetical order, although a few of the routines are grouped by "family" (the exec ... and spawn ... functions, for example) because they perform similar or related tasks.
Each function entry provides certain standard information. For instance, the entry for free
• Tells you which header file(s) cont~ins the prototype for free.
• Summarizes what free does.
• Gives the syntax for calling free.
• Gives a detailed description of how free is implemented and how it relates to the other memory-allocation routines.
• Lists other language compilers that include similar functions.
• Refers you to related Borland C++ functions.
The following sample library entry lists each entry section and describes the information it contains. The alphabetical listings start on page 10.
Sample function entry header file name
Function Syntax
The function is followed by the header file(s) containing the prototype for function or definitions of constants, enumerated types, and so on used by function.
Summary of what this function does.
function(modifier parameter[, .. . J);
This gives you the declaration syntax for function; parameter names are italicized. The [, ... J indicates that other parameters and their modifiers can follow.
Portability is indicated by marks (.) in the columns of the portability table.
A sample portability table is shown here:
Chapter 2, Run-time functions 9
Sample function entry
Remarks Return value See also
Example
abort
Function Syntax
Each entry in the portability table is described in the following table. Any additional restrictions are discussed in the Remarks section.
DOS
UNIX
Available for DOS.
Available under UNIX andbr POSIX.
Win 16 Compatible with 16-bit Windows programs running on Microsoft Windows 3.1, Windows for Workgroups 3.1, and Windows for Workgroups 3.11.
Win 32 Available to 32-bit Windows programs running on Win32s 1.0, and Windows NT 3.1 applications.
ANSI C Defined by the ANSI C Standard.
ANSI C++ Included in the ANSI C++ proposal.
OS/2 Available for OS/2.
If more than one function is discussed and their portability features are identical, only one row is used. Otherwise, each function is represented in a separate row.
This section describes what function does, the parameters it takes, and any details you need to use function and the related routines listed.
The value that function returns (if any) is given here. If function sets any global variables, their values are also listed.
Routines related to function that you might want to read about are listed here. If a routine name contains an ellipsis, it indicates that you should refer to a family of functions (for example, exec ... refers to the entire family of exec functions: execl, execle, execlp, execlpe, execv, execve, execvp, and execvpe).
The function examples have been moved into online Help so that you can easily cut-and-paste them to your own applications.
stdlib.h
Abnormally terminates a program.
void abort (void) ;
Remarks
Return value See also
abs
Function Syntax
Remarks
Return value
See also
access
Function Syntax
abort
abort causes an abnormal program termination by calling raise(SIGABRT). If there is no signal handler for SIGABRT, then abort writes a termination message ("Abnormal program termination") on stderr, then aborts the program by a call to _exit with exit code 3.
abort returns the exit code 3 to the parent process or to the operating system command processor.
assert, atexit, _exit, exit, raise, signal, spawn ...
stdlib.h
Returns the absolute value of an integer.
int abs (int x) i
abs returns the absolute value of the integer argument x. If abs is called when stdlib.h has been included, it's treated as a macro that expands to inline code.
If you want to use the abs function instead of the macro, include #undef abs in your program, after the #include <stdlib.h>.
This function can be used with bcd and complex types.
The abs function returns an integer in the range of
a
to INT_MAX, with the exception that an argument with the value INT_MIN is returned as INT_MIN. The values for INT_MAX and INT_MIN are defined in header file limits.h.bcd, cabs, complex, Jabs, labs
io.h
Determines accessibility of a file.
int access(const char *filenarne, int arnode)i
Chapter 2, Run-time functions 11