我试图提取两个 (int32_t) 值,并将它们放在一个 char 数组中。
int32_t version = getVersion();
if (version < 0)
{
return;
}
else
{
//first part of number needs to be shifted right
int32_t major = (((version) >>16) & 0xFFFF);
int32_t minor = ((version) & 0xFFFF);
// need to concatenate these two values, and place a "." between them
setVersion(...);//requires a char array, should for example be "1.1"
}
任何人都可以就最好的方法给我任何建议吗?请不要使用 std::strings。 我更喜欢 char 数组。
提前致谢
最佳答案
您可以使用 strstream
char v[255] = {};
{
std::strstream vs(v, 254);
vs << major << '.' << minor;
}
setVersion(v);
关于c++ - 将两个整数值连接成一个 char 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11274740/