草庐IT

const-char

全部标签

c++ - 将 `hana::string` 转换为 `constexpr const char (&)[]`

我有一些旧代码使用了与str_const非常相似的东西描述here和here做一些constexpr字符串操作。str_const是ScottSchurr描述的文字类型,可以从字符串文字构造,因为它具有来自constchar(&)[]的模板构造函数.我现在也有一些使用boost::hana的新代码.我希望能够参加hana::string并创建一个str_const那是指它。最简单的方法是转换hana::string到constexprconstchar(&)[].(实际上,在这一点上这不是最简单的方法,最简单的方法肯定是在我的str_const实现中添加一个新的模板构造函数。但在这一点

c++ - 在类声明中初始化 const 成员变量时 Debug模式下的异常

#include#include#include#includeclassX{public:X(){std::cout>ValidatorType;constValidatorTypem_validators=ValidatorType{{"some-string",[](){//validationcodestd::cout以上代码使用Xcode7.2.1和Clang7.0.2在OSX上以调试和Release模式成功构建和运行。它还使用VisualStudioExpress2013forWindowsDesktop在Windows7上以Release模式成功构建和运行。但是,在Win

c++ - const、span 和迭代器问题

我尝试编写一个迭代器,通过索引遍历容器。It和一个constIt两者都允许更改容器的内容。Const_it和一个constConst_it两者都禁止改变容器的内容。在那之后,我尝试写一个span在一个容器上。对于类型T这不是const,两者都是constspan和span允许更改容器的内容。两者constspan和span禁止改变容器的内容。代码无法编译,因为://*thisisconstwithinaconstmethod//ButItrequiresanon-const*thishere.//SothecodedoesnotcompileItbegin()const{returnI

c++ - 避免接受 lambda 的方法的 const/non-const 重复

classFrame表示像素类型为P的图像.由于底层数据缓冲区格式的多种灵active,遍历其像素的算法并非易事。template//Pispixeltype;RM=is_row_majorclassFrame{//...templatevoiditerate(Ff){//iterateinawaythatisperformantforthisbufferif(stride==(RM?size.w:size.h)){auton=size.area();for(index_tk=0;k(stride)*(RM?size.h:size.w);for(index_tk0=0;k0我希望能够同

c++ - 需要帮助调试从 const char* 到 char* [-fpermissive] 的无效转换

我是c++的新手,不知道为什么会这样......第105行我收到此错误从constchar*到char*的无效转换[-fpermissive]第113行我收到从âconstchar*到char*[-fpermissive]的无效转换错误#include#include#includeusingnamespacestd;characWordWrap[1024];characPrint[1024];BasicConsole::BasicConsole(char*szName):ZFSubSystem(szName){m_iMaxWidth=50;//TEXT_MAX_LENGHT;m_bL

c++如何运行其内容存储在char数组中的.exe文件?

我正在制作一个特定的程序,我只是想知道我是否可以这样做:在WINDOWS上运行一个文件,其内容存储在一个字符数组中。这是读取可执行文件并将其存储在字符数组中的代码:filetoopen.open(C:\blahlbah.exe,ios::binary);filetoopen.seekg(0,ios::end);length=filetoopen.tellg();filetoopen.seekg(0,ios::beg);buffer=newchar[length];filetoopen.read(buffer,length);filetoopen.close();我听说过有关RunPE的

c++ - 如何*正确*地将 std::string 转换为无符号 char[] 数组。我想我做错了,有人指出我正确的方向吗?

我目前正在对网络协议(protocol)进行逆向工程,并且我编写了一个小型解密协议(protocol)。我曾经将数据包的字节定义为一个无符号字符数组,如下所示:unsignedcharbuff[]="\x00\xFF\x0A"etc.为了不对每个数据包多次重新编译程序,我制作了一个小型GUI工具,它可以从字符串中获取\xFF表示法中的字节。我通过以下方式做到了这一点:intlength=int(stencString.length());unsignedchar*buff=newunsignedchar[length+1];memcpy(buff,stencString.c_str()

c++ - 在自定义 const native C++ 容器类上支持 "for each"

我想实现一个简单的nativeC++固定容量数组模板类,为了方便起见支持基于范围的“foreach”语法,开销最小。我在const实例上支持它时遇到问题。有了这个实现:templateclassList{public:List(){mSize=0;}constT*begin()const{returnmItems;}constT*end()const{returnmItems+mSize;}T*begin(){returnmItems;}T*end(){returnmItems+mSize;}private:size_tmSize;TmItems[Capacity];};和这种用法:c

c++ - Qt错误: 'const class QString' has no member named 'toStdString'

我收到此错误error:'constclassQString'hasnomembernamed'toStdString'虽然QString有它。(link).代码std::stringMessage::toStdString()const{returnm_string.toStdString();} 最佳答案 直接从这里复制答案:HowtoconvertQStringtostd::string?QStringqs;//EitherthisifyouuseUTF-8anywherestd::stringutf8_text=qs.toU

c++ - 通过 const 引用延长临时生命周期

C++我正在尝试了解const引用如何延长临时对象的生命周期。我正在运行oneoftheanswerstoWhatarethedifferencesbetweenpointervariableandreferencevariableinC++?中的代码片段并在VC11和g++4.8之间得到了冲突的结果。我在这里扩展了代码段:#includestructscope_test{~scope_test(){printf("scope_testdone!\n");}};intmain(){constscope_test&test=scope_test();printf("inscope\n")