Type header file in c++ and its function

6
Computer & Information Sciences University of Delaware C++ Header Files and Standard Functions (This info is taken from Appendix C of the nice book Data Abstraction and Problem Solving with C++, 3rd ed., by F. M. Carrano & J.J. Prichard.) Here is a list of commonly used C++ headers. If an older version of the header exists, its name is shown in parentheses. cassert (assert.h) This library contains only the function assert. You use assert(assertion); to test the validity of an assertion. If assertion is false, assertwrites an error message and terminates program execution. You can disable all occurrences of assert in your program by placing the directive #define NDEBUG before the include directive. cctype (ctype.h) Most functions in this library classify a given ASCII character as a letter, a digit, and so on. Two other functions convert letters between uppercase and lowercase. The classification functions return a true value if ch belongs to the specified group; otherwise they return false. isalnum(ch) Returns true if ch is either a letter or a decimal digit isalpha(ch) Returns true if ch is a letter iscntrl(ch) Returns true if ch is a control character (ASCII 127 or 0 to 31)

Transcript of Type header file in c++ and its function

Page 1: Type header file in c++ and its function

Computer & Information SciencesUniversity of Delaware

C++ Header Files and Standard Functions

(This info is taken from Appendix C of the nice book Data Abstraction and Problem Solving with C++, 3rd ed., by F. M. Carrano & J.J. Prichard.)

Here is a list of commonly used C++ headers. If an older version of the header exists, its name is shown in parentheses.

cassert (assert.h)

This library contains only the function assert. You useassert(assertion);

to test the validity of an assertion. If assertion is false, assertwrites an error message and terminates program execution. You can disable all occurrences of assert in your program by placing the directive#define NDEBUGbefore the include directive.

cctype (ctype.h)

Most functions in this library classify a given ASCII character as a letter, a digit, and so on. Two other functions convert letters between uppercase and lowercase. 

The classification functions return a true value if ch belongs to the specified group; otherwise they return false.isalnum(ch) Returns true if ch is either a letter or a decimal digitisalpha(ch) Returns true if ch is a letteriscntrl(ch) Returns true if ch is a control character (ASCII 127 or 0 to 31)isdigit(ch) Returns true if ch is a decimal digitisgraph(ch) Returns true if ch is printable and nonblankislower(ch) Returns true if ch is a lowercase letterisprint(ch) Returns true if ch is printable (including blank)ispunct(ch) Returns true if ch is a punctuation character

isspace(ch) Returns true if ch is a whitespace character: space, tab, carriage return, new line, or form feed

isupper(ch) Returns true if ch is an uppercase letterisxdigit(ch) Returns true if ch is a hexidecimal digittoascii(ch) Returns ASCII code for ch

tolower(ch) Returns the lowercase version of ch if ch is an uppercase letter; otherwise returns ch

toupper(ch) Returns the uppercase version of ch if ch is a lowercase letter; otherwise returns ch

cfloat (float.h)

Page 2: Type header file in c++ and its function

Defines named constants that specify the range of floating-point values.

climits (limits.h)

Defines named constants that specify the range of integer values.

cmath (math.h)

The C++ functions in this library compute certain standard mathematical functions. These functions are overloaded to accomodate float, double, and long double. Unless otherwise indicated, each function has one argument, with the return type being the same as the argument type (either float, double, orlong double).acos Returns the arc cosineasin Returns the arc sineatan Returns the arc tangentatan2 Returns the arc tangent x/y for arguments x and yceil Rounds upcos Returns the cosinecosh Returns the arc cosineexp Returns ex

fabs Returns the absolute valuefloor Rounds downfmod Returns x modulo y for arguments x and yfrexp For arguments x and eptr, where x = m * 2e, returns m and sets eptr to point to eldexp Returns x * 2e , for arguments x and elog Returns the natural loglog10 Returns the log base 10

modf For arguments x and iptr, returns the fractional part of x and sets iptr to point to the integer part of x

pow Returns xy , for arguments x and ysin Returns the sinesinh Returns the hyperbolic sinesqrt Returns the square roottan Returns the tangenttanh Returns the hyperbolic tangent

cstdlib (stdlib.h)

abort Terminates program execution abnormallyabs Returns the absolute value of an integeratof Converts a string argument to floating pointatoi Converts a string argument to an integerexit Terminates program executionrand() Generates an unsigned int between 0 and RAND_MAX, a named constant defined in cstdlib header filesrand(unsigned n) Seeds the rand() function so that it generates different sequences of random numbers. srand is often used in conjunction with the time function from the ctime library. For example, srand(time(0));

Page 3: Type header file in c++ and its function

cstring (string.h)

This library enables you to manipulate C strings that end in the char '\0', the null char. Unless noted otherwise, these functions return a pointer to the resulting string in addition to modifying an appropriate argument. The argument ch is a character, n is an integer, and the other arguments are strings, which usually means they are names of a char array, but can be string constants in some cases. For example, strcmp("Hello", "Goodbye");strcat(toS, fromS) Copies fromS to the end of toSstrncat(toS, fromS, n) Copies at most n characters of fromS to the end of toS and appends \0strcmp(str1, str2) Returns an integer that is negative if str1 < str2, zero if str1 == str2, and positive if str1 > str2stricmp(str1, str2) Behaves like strcmp, but ignores casestrncmp(str1, str2, n) Behaves like strcmp, but compares the first n characters of each stringstrcpy(toS, fromS) Copies fromS toSstrncpy(toS, fromS, n) Copies n characters of fromS to toS, truncating or padding with \0 as necessarystrspn(str1, str2) Returns the number of initial consecutive characters of str1 that are not in str2strcspn(str1, str2) Returns the number of initial consecutive characters of str1 that are in str2strlen(str) Returns the length of str, excluding \0strlwr(str) Converts any uppercase letters in str to lowercase without altering other charactersstrupr(str) Converts any lowercase letters in str to uppercase without altering other charactersstrchr(str, ch) Returns a pointer to the first occurrence of ch in str; otherwise returns NULLstrrchr(str, ch) Returns a pointer to the last occurrence of ch in str; otherwise returns NULLstrpbrk(str1, str2) Returns a pointer to the first character in str1 that also appears in str2; otherwise returns NULLstrstr(str1, str2) Returns a pointer to the first occurrence of str2 in str1; otherwise returns NULLstrtok(str1, str2) Finds the next token in str1 that is followed by str2, returns a pointer to the token and writes NULL immediately after the token in str1

ctime

Defines functions for manipulating time and dates.

exception

Defines classes, types, and functions that relate to exception handling. A portion of the class exception is shown below. class exception { public: exception() throw(); virtual -exception() throw(); exception &operator=(const exception %exc) throw();

Page 4: Type header file in c++ and its function

virtual const char *what() const throw(); }

fstream (fstream.h)

Declares the C++ classes that support file I/O.

iomanip (iomanip.h)

The manipulation in this library affect the format of steam operations. Note that iostream contains additional manipulators.setbase(b) Setts number base to b = 8, 10, or 16setfill(f) Sets fill character to fsetprecision(n) Sets floating-point precision to integer nsetw(n) Sets field width to integer n

iostream (iostream.h)

The manipulators in this library affect the format of stream operations. Note that iomanip contains additional manipulators.dec Tells subsequent operation to use decimal representationend1 Inserts new-line character \n and flushes output streamends Inserts null character \0 in an output streamflush Flushes an output streamhex Tells subsequent I/O operations to use hexadecimal representationoct Tells subsequent I/O operation to use octal representationws Extracts whitespace characters on input stream

string

This library enables you to manipulate C++ strings. Described here is a selection of the functions that this library provides. In addition, you can use the following operators with C++ strings: =, +, ==, !=, <, <=, >, >=, <<, and >>. Note that positions within a string begin at 0.erase() Makes the string emptyerase(pos, len) Removes the substring that begins at position pos and contains len charactersfind(subString) Returns the position of a substring within the stringlength() Returns the number of characters in the string (same as size)replace(pos, len, str) Replaces the substring that begins at position pos and contains len characters with the string strsize() Returns the number of characters in ths string (same as length)substr(pos, len) Returns the substring that begins at position pos and contains len characters