所以我知道有符号和无符号int之间的区别在于,有一些用于表示数字是正数还是负数,但这如何适用于char?角色怎样才能是积极的还是消极的?
下面的代码编译,但char类型的行为与int类型的行为不同.
特别是
   cout << getIsTrue< isX<int8>::ikIsX  >() << endl;
   cout << getIsTrue< isX<uint8>::ikIsX  >() << endl;
   cout << getIsTrue< isX<char>::ikIsX  >() << endl;
导致三种类型的模板的3个实例化:int8,uint8和char.是什么赋予了?
对于ints来说也是如此:int和uint32导致相同的模板实例化,而signed int则是另一个.
原因似乎是C++将char,signed char和unsigned char视为三种不同的类型.而int与signed int相同.这是对的还是我错过了什么?
#include <iostream>
using namespace std;
typedef   signed char       int8;
typedef unsigned char      uint8;
typedef   signed short      int16;
typedef unsigned short     uint16;
typedef   signed int        int32;
typedef unsigned int       uint32;
typedef   signed long long  int64;
typedef unsigned long long uint64;
struct TrueType {};
struct FalseType {};
template <typename T>
struct isX …鉴于有符号和无符号整数使用相同的寄存器等,并且只是不同地解释位模式,而C字符基本上只是8位整数,C中有符号和无符号字符之间的区别是什么?我理解char的签名是实现定义的,我根本无法理解它是如何产生影响的,至少当char用于保存字符串而不是数学时.
我正在写一个算法要求我将值插入到std::string无符号的1字节整数(0  -  255)中,并要求我将字符串的各个字符的值打印为整数,但是,我不断得到负值.我的猜测是,字符存储在带std::string符号的1字节字符(-128到127)中,因此,为什么我得到输出的负值.负值是我插入的正值的等效负形式.我做了一些研究,但似乎无法找到一种方式来表达我的问题,产生我正在寻找的答案.