一、字符串操作
1、原型:strcpy(char destination[], const char source[]); 功能:将字符串source拷贝到字符串destination中 
 例程:  
  #include <iostream.h> 
 #include <string.h> 
 void main(void) 
 { 
   charstr1[10] = { "TsinghuaOK"}; 
   charstr2[10] = { "Computer"}; 
   cout<<strcpy(str1,str2)<<endl; 
 }运行结果是:Computer 
 第二个字符串将覆盖掉第一个字符串的所有内容! 
 注意:在定义数组时,字符数组1的字符串长度必须大于或等于字符串2的字符串长度。不能用赋值语句将一个字符串常量或字符数组直接赋给一个字符数组。所有字符串处理函数都包含在头文件string.h中。2、原型:strncpy(chardestination[], const char source[], int numchars);
strncpy:将字符串source中前numchars个字符拷贝到字符串destination中。 
 strncpy函数应用举例 
 原型:strncpy(chardestination[], const char source[], int numchars); 
 功能:将字符串source中前numchars个字符拷贝到字符串destination中 
 例程: #include <iostream.h> 
 #include <string.h> 
 void main(void) 
 { 
   charstr1[10] = { "Tsinghua "}; 
   charstr2[10] = { "Computer"}; 
   cout<<strncpy(str1,str2,3)<<endl; 
 }运行结果:Comnghua 
 注意:字符串source中前numchars个字符将覆盖掉字符串destination中前numchars个字符!3、原型:strcat(chartarget[], const char source[]); 功能:将字符串source接到字符串target的后面 
 例程: 
 #include <iostream.h> 
 #include <string.h> 
 void main(void) 
 { 
   charstr1[] = { "Tsinghua "}; 
   charstr2[] = { "Computer"}; 
   cout<<strcpy(str1,str2)<<endl; 
 }运行结果:TsinghuaComputer
注意:在定义字符数组1的长度时应该考虑字符数组2的长度,因为连接后新字符串的长度为两个字符串长度之和。进行字符串连接后,字符串1的结尾符将自动被去掉,在结尾串末尾保留新字符串后面一个结尾符。
4、原型:strncat(chartarget[], const char source[], int numchars); 功能:将字符串source的前numchars个字符接到字符串target的后面 
 例程:#include <iostream.h> 
 #include <string.h> 
 void main(void) 
 { 
   charstr1[] = { "Tsinghua "}; 
   charstr2[] = { "Computer"}; 
   cout<<strncat(str1,str2,3)<<endl; 
 }运行结果:TsinghuaCom
5、原型:strlen(const char string[] ); 功能:统计字符串string中字符的个数 
 例程: #include <iostream.h> 
 #include <string.h> 
 void main(void) 
 { 
   char str[100];  
   cout <<"请输入一个字符串:"; 
   cin >>str; 
   cout <<"The length of the string is:"<<strlen(str)<<"个"<<endl; 
 }运行结果Thelength of the string is x (x为你输入的字符总数字)
注意:strlen函数的功能是计算字符串的实际长度,不包括'\0'在内。另外,strlen函数也可以直接测试字符串常量的长度,如:strlen("Welcome")。
6、char *strrev(char *string);  将字符串string中的字符顺序颠倒过来. NULL结束符位置不变.  返回调整后的字符串的指针. 
7、char *_strupr(char *string);  将string中所有小写字母替换成相应的大写字母, 其它字符保持不变.  返回调整后的字符串的指针. 
8、char *_strlwr(char *string);  将string中所有大写字母替换成相应的小写字母, 其它字符保持不变.  返回调整后的字符串的指针. 
参考:http://www.jb51.net/article/37410.htm
 
二、字符串类型转换 
1、float转为char*
float slicePos=100.02f;
charsliceP[10];
sprintf(sliceP,"%.2f",slicePos);
2、CString转为char*
CStringtmp=”hello”;
char*partsRoot = tmp.GetBuffer(tmp.GetLength());
3、float转为CString
CString str;
str.Format("%f",value);
4、int转为CString
CString str;
str.Format("%d",value);
5、char*转为CString
直接赋值即可
char name[] = "hello";
CString str = name;
6. CString转为string
string = CT2CA(CString);