1、string 转 intc++
头文件“stdlib.h”数组
atoi函数
这个函数是把char * 转换成int的。应该是属于标准库函数。在想把string 转换成int的时候,需要下面流程:spa
不能直接printf string,string为拓展类,连接错误。printf只能输出C的内置数据。code
string -> char * -> int
string
string a = "1234"; int b = atoi(a.c_str()); //c_str();转char []
功能是int->char *
,因此可以:it
itoa(int a,char *b[],int c) //a数据,b char[],c进制。
2、int写入char []
itoa在不能用的状况下,可用snprintf(buffer, sizeof(buffer), "%d", i)
2、char数组复制
char
* strcpy(
char
*strDest,
const
char
*strSrc )
{
assert
( (strDest != NULL) && (strSrc != NULL) );
char
*address = strDest;
while
( (*strDest++ = * strSrc++) != ‘\
0
’ );
return
address;
}
在库函数中,字符的赋值所采用的循环代码,只用了一行代码:while( (*strDest++ = * strSrc++) != ‘\0’ );循环
3、int []逆序数据
reverse(a,a+n);di