Standard Library Functions
The prototypes for the some common functions in the C++ standard library are listed below. These prototypes and the functions definitions are declared within the std
namespace. To access one of these functions, we #include
its parent header file and either expose the entire namespace (using namespace std;
) or add the std::
prefix to the function identifier.
C Library
<cstdio>
- Standard and File Input Output
int scanf(const char* format, ...)
: Read data from standard inputint printf(const char* format, ...)
: Send data to standard outputint fscanf(FILE* stream, const char* format, ...)
: Read data from a file streamint fprintf(FILE* stream, const char* format, ...)
: Send data to a file stream
<cstring>
- C-Style Null-Terminated Strings
size_t
: Non-negative integer typesize_t strlen(const char* str)
: The number of characters in a C-style null-terminated stringchar* strcpy(char* destination, const char* source)
: Copy C-style null-terminated string fromsource
address todestination
addresschar* strcat(char* destination, const char* source)
: Concatenate C-style null-terminated string fromsource
address to the string at thedestination
addressint strcmp(const char* str1, const char* str2)
: Compare C-style null-terminated strings at two addresses
<cstdlib>
- General Utilities
int abs(int i)
: Absolute value ofi
int atoi(const char* str)
: Convert C-style null-terminated string (str
) to an integerint rand()
: Generate a random number
<cmath>
- Numerics
double abs(double x)
: Absolute value ofx
float abs(float x)
: Absolute value ofx
double pow(double base, double exponent)
: Raisesbase
to the power ofexponent
double sqrt(double x)
: Square root ofx
<cctype>
- Character Handling
int toupper(int c)
: Convertsc
to upper caseint tolower(int c)
: Convertsc
to lower caseint isupper(int c)
: Isc
upper case?int islower(int c)
: Isc
lower case?int isalpha(int c)
: Isc
alphabetic?int isdigit(int c)
: Isc
a numeric digit?
Input Output Library
<iostream>
- Standard Input Output Objects
streamsize
: Integer typefmtflags
: Format flags typechar fill(char c)
: Set fill character toc
fmtflags setf(fmtflags f)
: Set format tof
fmtflags unsetf(fmtflags f)
: Unset format forf
streamsize width(streamsize w)
: Set field width tow
streamsize precision(streamsize p)
: Set floating-point precision top
bool good() const
: Good bit is setbool eof() const
: End of file bit is setbool fail() const
: Fail file bit is setbool bad() const
: Bad bit is setbool eof() const
: End of file bit is setvoid clear()
: Set error state to good
<iomanip>
- Parametric Manipulators
setfill(char c)
: Set fill character toc
setw(int w)
: Set field width tow
setprecision(int p)
: Set floating-point precision top
<fstream>
- File Input Output Objects
void open(const char* f, ...)
: Open file namedf
and associate it with the current objectvoid close()
: Close file associated with current object