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.