我的代码如下
std::ostringstream convert;
typedef struct
{
uint8_t arr[36];
}bcmolt_bin_str_36;
上面是UI必须分配一个大数字(注册ID)的结构
int main()
{
bcmolt_bin_str_36 registration_id;
registration_id.arr[36] = 313233343536373839313233343536373839313233343536373839313830383038303931;
我抄对号码了吗? 然后转换为字符串
for(a = 0; a < 36; a++) {
convert << (int)registration_id.arr[a];
}
std::string registration_id_str = convert.str();
printf("Reg ID is %s\n",registration_id_str.c_str());
return 0;
}
获取此问题和输出
test.cpp:21:27: warning: integer constant is too large for its type
registration_id.arr[36] = 313233343536373839313233343536373839313233343536373839313830383038303931;
^
test.cpp: In function ‘int main()’:
test.cpp:21:25: warning: large integer implicitly truncated to unsigned type [-Woverflow]
registration_id.arr[36] = 313233343536373839313233343536373839313233343536373839313830383038303931;
^
osboxes@mars~ $ ./hello
Reg ID is 2000000029136400000000000000000000020812640
如何整改?
你想做什么也不清楚。
注册号似乎是错误地转换为数字的字符串。 31
是字符'1'
的十六进制代码,32
是'2'
的十六进制代码,以此类推。 我怀疑你是在对这个“数”进行算术运算。 您可能必须使用std::string
而不是unit_8
数组。
#include <string>
typedef struct
{
std::string reg;
}
bcmolt_bin_str_6;
int main()
{
bcmolt_bin_str_6 registration_id;
registration_id.reg = "123456378912345637891234563789183083083091"; // reg[0] == 31, reg[1] == 32
}