C++ 中类型转换 xmlChar * 与Char * 转换,Char *与int 转换,Char *与Float转换,int 与portNumBits转换

来源:互联网 发布:mac sacd 编辑:程序博客网 时间:2024/06/07 05:01

使用libxml2  

得到一个节点的内容: 
xmlChar *value = xmlNodeGetContent(node)


1、XmlChar 转换成Char

char * stream = (char *) value;

2、Char *与  int 转换

int x = atoi(stream);

#include "stdio.h"#include "stdlib.h"main(){ char *p="1234567"; int x; x=atoi(p);//转成整形 printf("%d\n",x);}若果楼主写的是char*p="1234.567"则是 x=atof(p);C语言库函数名: atoi  功 能: 把字符串转换成整型数.  名字来源:array to integer 的缩写.   函数说明: atoi()会扫描参数nptr字符串,如果第一个字符不是数字也不是正负号返回零,否则开始做类型转换,之后检测到非数字或结束符 \0 时停止转换,返回整型数。   原型: int atoi(const char *nptr);  需要用到的头文件: #include <stdlib.h> 而atof是将字串转换成浮点型数
3、Char * 与float 转换

char * p ="1234.567";

int x = atof(p);

4、int 与 portNumBits转换

int  a = 554;

portNumBits n = (portNumBits) a



0 0