VC ++ type conversion (zz)

Source: Internet
Author: User
Tags floor function
I. String Conversion

1. Convert cstring to integer int
Cstring STR = _ T ("12345 ");
// Atoi. I don't know if there are other functions. Currently, I only know that there are atoi
Atoi (lpcstr) Str); // convert it to const char *

 

2. convert a cstring to a char array (char *).
Char buffer [256];
Cstring STR;
1), // strcpy Method
Strcpy (buffer, str. getbuffer ());
Str. releasebuffer ();
2) // forced conversion method
Buffer = (lptstr) (lpctstr) STR;
3), // sprintf Method
Sprint (buffer, "% s", STR)
// In vc2005, you need to set the project to multibyte.

See: to commemorate the conversion of vc2005 cstring to char * event

Ii. numerical processing

1. Floating Point Number integer Method

1) directly assign values to integer variables. For example:
Int I = 2.5; or I = (INT) 2.5; this method uses rounding.

2) use floor function. Floor (x) returns an integer of X. For example:
Floor (2.5) = 2
Floor (-2.5) =-2
3) use the ceil function. Ceil (x) returns the smallest integer not greater than X. For example:
Ceil (2.5) = 2
Ceil (-2.5) =-3

4) Calculate the remainder %, fmod function.
8% 3 = 2. Applicable to Integers
Fmod (8.1, 3) = 2.1. Applicable to floating point numbers. After searching for this function for a long time, I wrote it myself. I don't believe C ++ has no tape, but I still find it.

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.