可能重复:
C/C++中的字符大小('a')
以下程序
#include <stdio.h>
int main()
{
printf("%d\n", sizeof('\0'));
printf("%d\n", sizeof(0));
}
Run Code Online (Sandbox Code Playgroud)
用gcc输出编译
4
4
Run Code Online (Sandbox Code Playgroud)
和g ++
1
4
Run Code Online (Sandbox Code Playgroud)
为什么会这样?我知道这不是编译器的事情,而是C和C++之间的区别,但是原因是什么?
所以我有一个两个char数组
unsigned char v[2];
Run Code Online (Sandbox Code Playgroud)
我想将v [0]的值显示为0到255之间的数字但是
cout << v[0] << endl; //prints some garbage
cout << (void*)v[0] << endl; //prints the right thing but in hex
Run Code Online (Sandbox Code Playgroud)
所以我试过了
cout << (int)v[0] << endl;
Run Code Online (Sandbox Code Playgroud)
要么
printf("%d\n", v[0]);
Run Code Online (Sandbox Code Playgroud)
这显示了我想要的,但我完全不喜欢它.我根本不明白的是为什么这不起作用:
cout << reinterpret_cast<int>(v[0]) << endl; //compiler error
Run Code Online (Sandbox Code Playgroud) 我想构建一个使用GNU Autotools使用ZipArchive的共享库,但我遇到了这个问题:
Warning: linker path does not have real file for library -lziparch. I have the capability to make that library automatically link in when you link to this library. But I can only do this if you have a shared version of the library, which you do not appear to have because I did check the linker path looking for a file starting with libziparch and none of the candidates passed a file format test using a file magic. …