Common types of conversions
int turn CString:
CString string;
int ivalue=100;
String. Format (_t ("%d"), ivalue);
MessageBox (string);
String has a value of ' 100 '
CString int:
CString str= "1";
int N=atoi (str. GetBuffer (0));
char * Turn CString:
Char sz[128];
CString str;
Str. Format ("%s", SZ);
Cstring.format ("%s", char *)
==========
Cstring.format ("%s", char*);
CString strtest;
char * CHARPOINT;
Charpoint= "Give string a value";
Strtest=charpoint; Direct Pay Value
CString Turn char *:
CString str;
int NLENGTH=STR. GetLength ();
char * sz=new char[nlength];
Sz=str. GetBuffer (0);
==========================
(LPCSTR) CString
Float Turn CString:
float f=0.0;
CString str;
Str. Format ("%f", f);
CString to Float:
CString str= "0.0";
float F=atof (str. GetBuffer (0));
String Turn CString
Cstring.format ("%s", String.c_str ());
Using C_str () is indeed better than data ().
char* Turn int
#include <stdlib.h>
int atoi (const char *nptr);
Long Atol (const char *nptr);
Long Long Atoll (const char *nptr);
Long Long Atoq (const char *nptr);
CString Turn string
String s (Cstring.getbuffer ());
GetBuffer () must be releasebuffer (), otherwise there is no space to free the buffer.
int turn char *
There is a function in the Stdlib.h itoa ()
Usage of itoa:
Itoa (i,num,10);
I need to convert numbers into characters
A variable that saves characters after NUM conversion
10 The cardinality of the conversion number (in) 10 means to convert the number in 10. It can be 2,8,16, etc. you like the type of the system
Prototype: char *itoa (int value, char* string, int radix);
Instance:
#include "Stdlib.h"
#include "stdio.h"
Main ()
{
int i=1234;
Char s[5];
Itoa (i,s,10);
printf ("%s", s);
GetChar ();
}
String char *
Char *p = STRING.C_STR ();
String AA ("AAA");
Char *c=aa.c_str ();
String Mngname;
Char t[200];
memset (t,0,200);
strcpy (T,mngname.c_str ());