草庐IT

Unsigned

全部标签

c++ - 是 unsigned char ('0' ) 合法的 C++

以下代码在VisualStudio中编译但在g++下编译失败。intmain(){inta=unsignedchar('0');return0;}unsignedchar()是一种有效的C++转换方式吗? 最佳答案 不,这是不合法的。函数式显式类型转换需要一个简单类型说明符,后跟一个带括号的表达式列表。(§5.2.3)unsignedchar不是简单类型说明符;这与James提出的问题有关.显然,如果unsignedchar是一个简单类型说明符,它将是合法的。解决方法是使用std::identity:templatestructid

c++ - 在 C++ 中将 unsigned char 转换为 int

我有一个包含值的变量unsignedchar,例如40。我想要一个int变量来获取该值。最简单、最有效的方法是什么?非常感谢。 最佳答案 unsignedcharc=40;inti=c;大概你的问题肯定不止于此...... 关于c++-在C++中将unsignedchar转换为int,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/10563642/

c++ - c++中 "unsigned long int"的最大值

我如何知道“unsignedlongint”类型的变量的最大可赋值是多少? 最佳答案 显而易见的方法是使用std::numeric_limits::max(); 关于c++-c++中"unsignedlongint"的最大值,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/18301685/

c++ - 使用 typedef'd uint 会导致错误,而 "unsigned int"不会...?

出于某种原因,当我在我的程序中将变量定义为“uint”而不是“unsignedint”时,它会出错。这看起来很奇怪,因为uint被定义为:typedefunsignedintuint;...所以我认为我可以互换使用这两者。更确切地说,我将返回“unsignedint”的函数的结果分配给一个uint变量,然后在vector调整大小调用中使用该uint...此时出错。即,我的代码看起来像这样:unsignedintgetUInt(){return3;}intmain(void){vector>vectVect(100000);for(uinti=0;i&myVect=vectVect[i]

c++ - 'comparison between signed and unsigned integer expressions' 真的会导致错误吗?

通常我使用的对象会有(有符号的)int参数(例如intiSize),这些参数最终会存储某物应该有多大。同时,我经常将它们初始化为-1以表示对象(等)尚未设置/尚未填充/尚未准备好使用。当我执行类似if(iSize>=someVector.size()){...}的操作时,我经常以警告结束comparisonbetweensignedandunsignedinteger.因此,名义上我不想使用unsignedint。在任何情况下这会导致错误或意外行为吗?如果不是:处理此问题的最佳方法是什么?如果我使用编译器标志-Wno-sign-compare我可能(假设地)错过我应该使用unsigne

c++ - 不一致的警告 "conversion from ' const unsigned char' to 'const float' requires a narrowing conversion”

VisualC++2017和gcc5.4产生conversionfrom'constunsignedchar'to'constfloat'requiresanarrowingconversion警告LineB但没有此代码段中的A行:#includeintmain(){constunsignedcharp=13;constfloatq=p;//LineAstd::cout这个警告有效吗?为什么LineB的处理方式与LineA不同? 最佳答案 警告有效,来自C++11narrowingconversions在aggregateiniti

c++ - Mat 到 unsigned char*

谁能告诉我如何转换Mat至unsignedchar*在OpenCV中,数据是否也是一个数组?另外,我想知道如何为vector>做同样的事情至float*从而使它成为数组的指针?谢谢。 最佳答案 如前所述,您应该使用cv::Mat的data成员:cv::Matm;...uchar*data=m.data;关于你的第二个问题:首先,当您从double转换为float时,您会丢失一些数据。并且没有现成的解决方案可以做到这一点,所以只需使用简单的循环并将vector复制到数组指针:float*toArray(vector>&arr){if(

c++ - 将 unsigned char* 转换为 const unsigned char* 后删除 []

粗略地说,我有一个包含constunsignedchar数组的类。此类的对象由一个特殊的工厂函数创建,该函数还负责(在堆上)构造数组。当在工厂函数中创建一个对象时,它会被赋予指向数组的指针。数组不会被复制,对象只会使用给定的指针。在销毁时,它将释放数组占用的内存块。classFoo{private:constunsignedchar*array;size_tsize;public:Foo(constunsignedchar*array,size_tsize):array(array),size(size){}~Foo(){delete[]array;}};Foo*factoryFunc

c++ - 未定义对 CryptoPP::AlignedAllocate(unsigned int) 的引用

我在c++linux中使用crypto++。这是我的简单代码:#include#include#include#include"crypto++/cryptlib.h"#include"crypto++/modes.h"#include"crypto++/filters.h"#include"crypto++/aes.h"#include"crypto++/osrng.h"#include"crypto++/strciphr.h"usingnamespacestd;usingnamespaceCryptoPP;ifstream::pos_typesize;char*memblock;i

c++ - 从 int 转换为 std::array<unsigned char, 1ul>::value_type 可能会改变其值

编译此程序时,-WconversionGCC参数产生标题中的警告:#include#include#includeintmain(){std::stringtest="1";std::arraybyteArray;byteArray[0]=byteArray[0]|test[0];return0;}这是我编译它的方式:g++--Wall-Wextra-Wconversion-pedantic-std=c++0xtest.cpp我使用的是GCC4.5。我在这里做违法的事情吗?它会在某些情况下引起问题吗?为什么|会产生一个int? 最佳答案