Program objective: to implement conversion between C ++ integer and character array strings

Source: Internet
Author: User

Environment: Dev-C ++

Source code:

# Include <iostream>
# Include <cstdlib>
Using namespace STD;
Main ()
{
Int I1 = 123, I2, I3;
Float F1;
Char c1 [20] = "234.45", C2 [20];
String S1 = "456", S2;
I2 = atoi (C1); // convert the character array to an integer
F1 = atof (C1); // converts a character array to a floating point type
ITOA (I1, C2, 10); // converts an integer to a character array. 10 indicates a decimal number.
Cout <"character array converted to integer:" <I2 <Endl;
Cout <"character array converted to floating point type:" <F1 <Endl;
Cout <"integer converted to character array:" <C2 <Endl;
Strncpy (C2, s1.c _ STR (), s1.length (); // convert a string to a character array
I3 = atoi (C2 );
Cout <"string converted to integer:" <I3 <Endl;
System ("pause ");
}
:

 

From http://hi.baidu.com/isokill/blog/item/7e0620d6146f11c9a8ec9a5a.html

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.