草庐IT

char_set

全部标签

c++ - 为什么我不能对另一个类的静态 char[] 执行 sizeof?

为什么下面的代码会产生编译错误?编辑:我的原始代码不清晰-我已将代码拆分成单独的文件...First.hclassFirst{public:staticconstchar*TEST[];public:First();};第一个.cppconstchar*First::TEST[]={"1234","5678"};First::First(){uint32_tlen=sizeof(TEST);//fine}确定First类中的大小似乎没问题,但是......第二.hclassSecond{public:Second();};第二个.cpp#include"First.h"Second::

c++ map/set 迭代器不可取消引用

我想向您请教,因为我是初学者,在互联网上找不到合适的答案。我收到此错误:调试断言失败-映射/设置迭代器不可取消引用在看起来像这样的行:pointA=active->pointNext(timeNext);使用pointNext()函数,我看到一切正常,并且关注active,我有:active=setS.data.end();更多信息:active是multiset::const_iteratorsetS有:setS.Q、setS.W、setS.T和setS.data,其中setS.data在方括号内有0。当我在.cpp文件中有多重迭代器声明时,在调试期间我无法进入以查看事件内部的内容,

char 数组上的 C++ 内存模型和竞争条件

基本上我很难理解这个:(来自BjarneFAQ)However,mostmodernprocessorscannotreadorwriteasinglecharacter,itmustreadorwriteawholeword,sotheassignmenttocreallyis``readthewordcontainingc,replacethecpart,andwritethewordbackagain.''Sincetheassignmenttobissimilar,thereareplentyofopportunitiesforthetwothreadstoclobbereac

c++ - 我可以将 unsigned char* 转换为 unsigned int* 吗?

error:invalidstatic_castfromtype‘unsignedchar*’totype‘uint32_t*{akaunsignedint*}’uint32_t*starti=static_cast(&memory[164]);我分配了一个字符数组,我想将4个字节作为32位int读取,但出现编译器错误。我知道我可以像这样移位:(start[0]它会做同样的事情,但这是很多额外的工作。是否可以通过某种方式将这四个字节转换为int? 最佳答案 static_cast旨在用于“行为良好”的转换,例如double->int

c++ - 标准是否保证 uint8_t、int8_t 和 char 都是唯一类型?

似乎以下内容可以保证通过(已询问here):#includestatic_assert(!std::is_same_v);static_assert(!std::is_same_v);引用cppreference[char]hasthesamerepresentationandalignmentaseithersignedcharorunsignedchar,butisalwaysadistincttype是否也保证int8_t和uint8_t根据显式签名类型定义未定义就char而言,因此也形成一组具有char?的3种不同类型#include#includestatic_assert(

c++ - 将字符指针 (char*) 转换为结构

我有一个结构://Custompacketstructure.structUserPacket{__int64pingTime;}CustomPacket;我已经想出了如何将它转换为char*。现在我想将char*转换回结构。有什么建议吗? 最佳答案 如果是C++:char*theCharPtr;//hasyourconverteddataUserPacket*fromChar=reinterpret_cast(theCharPtr); 关于c++-将字符指针(char*)转换为结构,我

包含 unsigned char 和 int 错误的 C++ 结构

好的,我的C++程序中有一个这样的结构:structthestruct{unsignedcharvar1;unsignedcharvar2;unsignedcharvar3[2];unsignedcharvar4;unsignedcharvar5[8];intvar6;unsignedcharvar7[4];};当我使用这个结构时,在“var6”之前添加了3个随机字节,如果我删除“var5”,它仍然在“var6”之前,所以我知道它总是在“var6”之前。但是如果我删除“var6”,那么3个额外的字节就没有了。如果我只使用其中包含int的结构,则没有额外的字节。所以unsignedcha

c++ - 奇怪的错误,set<int>::begin() 总是返回 const 迭代器

为什么set.begin()总是返回一个const迭代器而不是标准迭代器?35inttest(){36std::setmyset;37myset.insert(2);38myset.insert(3);39int&res=*myset.begin();40returnres;41}test.cpp:39:error:invalidinitializationofreferenceoftype‘int&’fromexpressionoftype‘constint’ 最佳答案 它没有返回const_iterator,而不是std::se

C++ : Why I can't print a const char* with sprintf?

我在这里错过了什么?这让我抓狂!我有一个返回constchar*的函数constchar*Notation()const{chars[10];intx=5;sprintf(s,"%d",x);returns;}现在在代码的另一部分我正在这样做:..........charstr[50];sprintf(str,"%s",Notation());..........但str保持不变。如果我这样做:..........charstr[50];str[0]=0;strcat(str,Notation());..........str设置正确。我想知道为什么sprintf没有按预期工作...

c++ - 我很困惑! C++ 中的 Char、Char* 或 String

当我使用char或char*时,visualstudio2012(11)只计算最后一个字符,例如:#include#includeintmain(){usingnamespacestd;charchName='Alex';cout它只显示“x”。我用的是正确的字符串strName="Alex"但是在那些参数为字符的函数中,字符串不能作为参数传递。在这种情况下,VS编译器说字符串不能转换为int。还告诉我char和char*之间有什么区别。我是一名PHP开发人员,而C++是如此令人困惑。请帮助我。 最佳答案 char一次只能保留1个字