Some library functions, constants, and header files commonly used in C + +

Source: Internet
Author: User
Tags mathematical functions strcmp

1 , common mathematical functions

Header file #include <math> or #include <math.h>

Function prototypes

Function

return value

int abs (int x)

To find the absolute value of an integer x

Absolute

Double ACOs (Double x)

Calculates the value of Arcos (x)

Calculation results

Double asin (Double x)

Calculates the value of Arsin (x)

Calculation results

Double Atan (Double x)

Calculates the value of arctan (x)

Calculation results

Double cos (double x)

Calculate the value of the cos (x)

Calculation results

Double cosh (Double x)

Computes the value of the hyperbolic cosine cosh (x) of X

Calculation results

Double exp (Double x)

The value of the request

Calculation results

Double fabs (Double x)

Absolute value of realistic number X

Absolute

Double Fmod (Double x)

Find the remainder of X/y

Double precision number of remainder

Long Labs (long X)

To find the absolute value of a long integer number

Absolute

Double log (double x)

Calculates the value of in (x)

Calculation results

Double log10 (Double x)

The calculated value

Calculation results

Double modf (double x, double *y)

Take the integer portion of x to the cell that Y points to

Small tree part of X

Double pow (double x, double y)

Find the value of X's Y-square

Calculation results

Double sin (double x)

Calculates the value of sin (x)

Calculation results

Double sqrt (double x)

The value of the request

Calculation results

Double tan (Double x)

Calculate the value of tan (x)

Calculation results

Fcvt

Convert a floating-point number to a string

2. String function (<string.h>)

String functions

All string functions are listed in the table below, and the function description takes the following conventions: S, T (char *) type parameters, CS, CT (const char*) type parameters (they all should represent strings). n represents a parameter of type size_t (size_t is an unsigned integer type), and C is an integer parameter (converted to char in a function):

Function prototypes

Meaning explanation

size_t strlen (CS)

Find the length of CS (not including ' strlen '), such as Chai =4

Char *strcpy (S,CT)

Copy the CT to S. Requires S to specify a large enough character array

Char *strncpy (s,ct,n)

Copy up to n characters from the CT to S. Requires S to specify a character array that is large enough. If the characters in the CT are not enough n, fill the empty characters in S.

Char *strcat (S,CT)

Copy the characters in the CT to the existing string in S. s should specify a character array that holds the string and is large enough.

Char *strncat (s,ct,n)

Copy up to n characters in CT to the existing string in S. s should specify a character array that holds the string and is large enough.

int strcmp (CS,CT)

Compare the size of the string CS and CT, return positive, 0, negative values when CS is greater than, equal to, and less than Ct.

int strncmp (CS,CT,N)

Compares the size of the string CS and CT to a maximum of n characters. When CS is greater than, equal to, less than CT, return positive, 0, negative value respectively.

Char *STRCHR (CS,C)

Searches for C in CS and returns the position of the first occurrence of C, expressed as a pointer to the position. return value NULL if C is not in CS

Char *STRRCHR (CS,C)

Searches for C in CS and returns the position of the last occurrence of C, and returns null if no

size_t strspn (CS,CT)

A sequence of all the characters in the CT that is determined by CS to return its length

size_t strcspn (CS,CT)

A sequence of all non-CT characters determined by CS to return its length

Char *strpbrk (CS,CT)

Searches for the characters in the CT in CS, returns the position of the first character that satisfies the condition, and returns null if none is present

Char *strstr (CS,CT)

Search for string CT (query substring) in CS, return the first occurrence of CT as a substring of CS, return NULL if CT does not appear in CS

Char *strerror (n)

Returns the error message string associated with error number n (pointer to the error message string)

Char *strtok (S,CT)

Search for words in s that are formed by characters in CT as separators

Store Operations

<string.h> also has a set of character array manipulation functions (store manipulation functions) whose names start with Mem and are implemented in an efficient manner. In the following prototype, the type of the parameter S and T is (void *), the type of CS and CT is (const void *), the type of n is the size_t,c type is int (converted to unsigned char).

Function prototypes

Meaning explanation

void *memcpy (S,ct,n)

Copy n characters from CT to S, return s

void *memmove (S,ct,n)

Copy n characters from CT to S, return s, two segments here allow overlap

int memcmp (CS,CT,N)

Compare n characters starting with CS and CT, and return values defined with strcmp

void *memchr (Cs,c,n)

Searches for the first occurrence of C in CS in the range of n characters, returns the pointer value for that position if found, otherwise returns null

void *memset (S,c,n)

Set s first n characters to C, return s

3. header file #include <stdlib> or # include <stdlib.h>

Function prototypes

Function

return value

Description

void abort (void)

Terminating program execution

Can't finish the job.

void exit (int)

Terminating program execution

Finish the job.

Double atof (const char *s)

Converts the string that s points to a real number

Real value

int atoi (const char *s)

Converts the string that s points to an integer

Integer value

Long Atol (const char *s)

Converts the string referred to by S to grow integers

Long Integer value

int rand (void)

Produces a random integer

Random integers

void Srand (unsigned int)

Initializing the random number generator

int system (const char *s)

The string pointed to by S as an executable file and executed

Max (A, B)

Ask for a large number in two numbers

Large number

parameter is any type

Min (A, B)

Ask for a decimal in two numbers

Decimal

parameter is any type

4. Header Files <climits> or <limits.h>

name expresses min. magnitude*
Char_bit Number of bits for a char object (Byte) 8
Schar_min Minimum value for an object of type signed Char -127
Schar_max Maximum value for an object of type signed Char 127
Uchar_max Maximum value for an object of type unsigned char 255
Char_min Minimum value for an object of type char Either schar_min or 0
Char_max Maximum value for an object of type char Either Schar_max or Uchar_max
Mb_len_max Maximum number of bytes in a multibyte character, for any locale 1
Shrt_min Minimum value for a object of type short int -32767
Shrt_max Maximum value for a object of type short int 32767
Ushrt_max Maximum value for a object of type unsigned short int 65535
Int_min Minimum value for an object of type int -32767
Int_max Maximum value for an object of type int 32767
Uint_max Maximum value for a object of type unsigned short int 65535
Long_min Minimum value for an object of type long int -2147483647
Long_max Maximum value for an object of type long int 2147483647
Ulong_max Maximum value for an object of type unsigned int 4294967295

Some library functions, constants, and header files commonly used in C + +

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.