草庐IT

char_type

全部标签

c++ - 我可以在不复制的情况下将 std::vector<char> 重新解释为 std::vector<unsigned char> 吗?

我引用了std::vector我想用作接受std::vector的函数的参数.我可以不复制就这样做吗?我有以下功能并且有效;但是我不确定是否真的发生了复制-有人可以帮助我理解这一点吗?是否可以使用std::move以避免复制还是它已经没有被复制?staticvoidshowDataBlock(boolusefold,boolusecolor,std::vector&chunkdata){char*buf=chunkdata.data();unsignedchar*membuf=reinterpret_cast(buf);std::vectorvec(membuf,membuf+chun

c++ - GCC 7,aligned_storage 和 "dereferencing type-punned pointer will break strict-aliasing rules"

我编写的代码在GCC4.9、GCC5和GCC6中没有警告。它在一些较旧的GCC7实验快照(例如7-20170409)中也没有警告。但在最近的快照(包括第一个RC)中,它开始产生关于别名的警告。代码基本上可以归结为:#includestd::aligned_storage::typestorage;intmain(){*reinterpret_cast(&storage)=42;}使用最新的GCC7RC编译:$g++-Wall-O2-cmain.cppmain.cpp:Infunction'intmain()':main.cpp:7:34:warning:dereferencingtyp

c++ - 设计建议——返回子类时避免 "invalid covariant return type"

我有以下情况:我指定一个纯虚函数:虚拟PredictedMatchPredictMatch(constMatch&match)const=0;我还有:类ImpactPredictedMatch:publicPredictedMatch现在,我想做的是:ImpactPredictedMatchPredictMatch(constMatch&match)const;在一个实现了之前的纯虚函数的类中。我原以为编译器会根据需要简单地转换返回的类型,但我得到:impact_predictor.h:18:24:错误:“虚拟ImpactPredictedMatchImpactPredictor::P

c++ - 我尝试使用 wchar_t、char16_t 和 char32_t 类型打印汉字,但无济于事。

我正在尝试使用wchar_t、char16_t和char32_t类型打印汉字中,没有成功(liveexample)#includeintmain(){charx[]="中";//ChinesecharacterwithunicodepointU+4E2Dchary[]=u8"中";wchar_tz=L'中';char16_tb=u'\u4e2d';char32_ta=U'\U00004e2d';std::cout 最佳答案 由于您在Linux系统上运行测试,源代码是UTF-8,这就是为什么x和y是一样的东西。这些字节被std::co

c++ - 错误 : argument of type char* is incompatible with parameter of type LPCWSTR

#include#includeusingnamespacestd;intmain(){char*file="d:/tester";WIN32_FIND_DATAFindFileData;HANDLEhFind;hFind=FindFirstFile(file,&FindFileData);//lineoferrorsaysargumentoftypechar*isincompatiblewithparameteroftypeLPCWSTR}我无法理解错误。错误是什么以及如何解决错误?我正在制作一个控制台应用程序,需要检查目录中是否有文件。 最佳答案

c++ - std::vector< std::vector<unsigned char>> 或 std::deque< std::vector<unsigned char>>?

我有一个现有的算法,如果可能的话,我需要稍微优化它。目前无法在此算法中进行大量更改。该算法适用于std::vector>的实例.它看起来像这样:typedefstd::vectorinternal_vector_t;std::vectorinternal_vectors;while(fetchinglotsofrecords){internal_vector_ttmp;//reads1Mbofcharsintmp...internal_vectors.push_back(tmp);//somemorework}//usethisinternal_vectors算法在internal_v

c++ - 如何识别代码中const char*和const char[]的类型?

constchar*s1="teststirg";constchars2[]="teststirg";我想要一个方法告诉我s1是“char*”而s2是“char[]”,怎么写这个方法? 最佳答案 使用模板:templateboolIsArray(T(&a)[SIZE]){returntrue;}templateboolIsArray(T*p){returnfalse;}这将在运行时进行评估。用法:if(IsArray(s1))...if(IsArray(s2))...如果有兴趣,您可以使用一些高级技术,它会告诉您这是编译时间。编辑:

c++ - C/C++ 中的 Char 数据类型

我正在尝试用Java调用C++DLL。在它的C++头文件中,有如下几行:#definea'102001'#defineb'102002'#definec'202001'#defined'202002'a、b、c、d分别是什么数据类型?它们是char还是char数组?我应该转换成什么Java中相应的数据类型? 最佳答案 作为Mysticial指出,这些是multicharacterliterals.它们的类型是依赖于实现的,但它可能是Javalong,因为它们使用48位。在Java中,您需要手动将它们转换为long:staticlon

c++ - boost .python : Argument types did not match C++ signature

我在python中调用C++函数时遇到一个奇怪的问题。我公开了一个我想从中调用函数的类:class_>("MyClass",init())//....def("someFunc",&MyClass::someFunc);我得到一个std::shared_ptr来自另一个类的成员变量,该类通过.def_readonly(...)公开当我尝试调用该函数时,出现以下错误:File"pytest.py",line27,intest_funccu.someFunc("string")Boost.Python.ArgumentError:PythonargumenttypesinMyClass.s

C++ 从 ‘const type* const’ 到 ‘type*’ 的无效转换

我有一个非常愚蠢的问题(我认为)。很长时间没有用C++编码,但我无法弄清楚这个问题。我有这个类:#includeclassNode{private:QList_adjacent;public:Node();boolisConnectedTo(Node*n)const;};isConnectedTo()的实现:boolNode::isConnectedTo(Node*n)const{return_adjacent.contains(n)&&n->_adjacent.contains(this);}我在return行中收到以下错误:Node.cpp:Inmemberfunction‘con