且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将char数组转换为单个整数?

更新时间:2023-11-11 20:55:04

you cast(char *)to(int)。你应该做的是将指针转换为整数,例如这样:

you cast (char*) to (int). What you should do is cast to pointer to integer, ie something like this:

t_num = *((int*) s_num));

但你真的应该把你的代码提取到自己的函数中,并确保

But really you should extract your code into it's own function and make sure that


  1. 字元序列正确

  2. sizeof(int)== 4

  3. 新C ++类型