Good C ++ Functions

Source: Internet
Author: User

Function: itoa (a, B, 10 );
Function: place the 10-digit value of a in string B;

C ++ code
# Include <iostream>
Using namespace std;
Int main ()
{
Char str [11];
Int I;
Cin> I;
Itoa (I, str, 10 );
Cout <str <endl;
Return 0;
}

# Include <iostream>
Using namespace std;
Int main ()
{
Char str [11];
Int I;
Cin> I;
Itoa (I, str, 10 );
Cout <str <endl;
Return 0;
}

Note: not all compilers are available!

Function: atoi (str );
Function: converts str to an integer and returns the C ++ code.
# Include <iostream>
Using namespace std;
Int main ()
{
Char str [11];
Int I;
Cin> str;
I = atoi (str );
Cout <I <endl;
Return 0;
}

# Include <iostream>
Using namespace std;
Int main ()
{
Char str [11];
Int I;
Cin> str;
I = atoi (str );
Cout <I <endl;
Return 0;
}

Note: although this function is a bit like itoa, it is worth noting that atoi has a return value. itoa only executes commands.

Others
C ++ code
Function isalpha (char) determines whether it is a letter
Function isdigit (char) to determine whether it is a number
The isalnum (char) function determines whether it is a number or letter.
The preceding three functions are in the header file ctype. h.

The strupr (char * s) function converts lowercase letters in string s to uppercase letters.
The strlwr (char * s) function converts uppercase letters in string s to lowercase letters.
Function strrev (char * s) reverses the order of all characters in string s (excluding NULL characters)

Function toupper, tolower case-sensitive Conversion
Function floor: int m = floor (sqrt (x) + 0.5) floating point error correction

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.