首页 » QT » 正文

char int等转化为string

如果不想自已写函数.可以这样玩

C语言版本

char str[100]; // could be less but i'm too lazy to look for the actual the max length of an integer
snprintf(str, sizeof(str), "%d", 0x77);
snprintf(str, sizeof(str), "0x77 was %d !", 0x77);

C++版本

#include  
std::string s = std::to_string(42);  // 需要C++11支持

QT版本

QString str;
str.sprintf("0x2F:%2x!\n",0x2F);

发表评论