草庐IT

char_type

全部标签

c++ - 使用 const char[] 或 const std::string 哪一个?

哪个对字符串文字更好,标准字符串还是字符数组?我的意思是说常量字符串,比如说constcharname[]="so";//ortouseconststringname="so"; 最佳答案 对于字符串文字,并且仅对于来自文字的字符串常量,我会使用constchar[]。std::string的主要优点是它有免费的内存管理,但这不是字符串文字的问题。它是文字的实际类型,它可以直接用于任何需要旧C样式空终止字符串或C++字符串(隐式转换开始)的API。您还可以通过使用数组而不是指针来获得编译时大小的实现。现在,在定义函数接口(inter

c++ - 枚举 "does not name a type' 的问题

g++(Ubuntu/Linaro4.4.4-14ubuntu5)4.4.5我有一个问题,我似乎找到了我得到这个错误的方法。文件statemachine.h#ifndefSTATEMACHINE_H_INCLUDED#defineSTATEMACHINE_H_INCLUDED#include"port.h"enumstate{ST_UNINITIALIZED=0x01,ST_INITIALIZED=0x02,ST_OPENED=0x03,ST_UNBLOCKED=0x04,ST_DISPOSED=0x05};voidstate_machine(eventevt,port_t*port)

.NET System::String 到存储在 char* 中的 UTF8 字节

我正在将一些非托管C++代码包装到.NET项目中。为此,我需要将System::String转换为存储在char*中的UTF8字节。我不确定这是否是最好的或什至是正确的方法,如果有人可以看一下并提供反馈,我将不胜感激。谢谢,/大卫//CopyintoblankVisualStudioC++/CLRcommandlinesolution.#include"stdafx.h"#includeusingnamespaceSystem;usingnamespaceSystem::Text;usingnamespaceSystem::Runtime::InteropServices;//Test

C++ 标准 : default "const T& value" in vector constructor for type 'int'

explicitvector(size_typen,constT&value=T(),constAllocator&=Allocator());vectorvec(10);cout::const_iteratoriter=vec.begin();iter!=vec.end();++iter){coutVS2010的输出:vec.size:100000000000问题>:根据最新的C++标准,当我们使用vectorObject(size_type)定义一个vector对象时,默认的int值是多少?在这里你可以看到,VS2010输出0作为默认的int值。但我不知道这是否是C++标准所要求的

RabbitMQ(十二)Cannot deserialize value of type `java.lang.String` from Object value 报错整理

目录1.核心报错内容:2.完整报错内容:3.报错原因:4.解决方案:消息接收类型错误1.核心报错内容:Cannotdeserializevalueoftypejava.lang.StringfromObjectvalue(tokenJsonToken.START_OBJECT)2.完整报错内容:org.springframework.amqp.rabbit.listener.exception.FatalListenerExecutionException:Illegalnullidinmessage.Failedtomanageretryformessage:(Body:'[B@7f8bf9

c++ - std::vector<T>::value_type 的正确行为

在对一些使用std::vector::value_type的模板代码中的一些错误摸不着头脑之后,我追踪到了以下内容。这是符合标准的正确行为,还是MSVC2012CTP的问题?typedefstd::vector::value_typet1;typedefstd::vector::value_typet2;static_assert(!std::is_same::value,"hmmm");上述断言失败。 最佳答案 value_type的std::vector是T(§23.3.6.1)。is_same的值将简历限定符考虑在内(§20.

c++ - 在 while 循环中递增 *char 的指针

这是我的:char*input=newchar[input_max]char*inputPtr=iput;我想使用inputPtr来遍历输入数组。但是我不确定什么能正确检查我是否已经到达字符串的末尾:while(*inputPtr++){//Somecode}或while(*inputPtr!='\0'){inputPtr++;//Somecode}还是更优雅的选择? 最佳答案 假设输入字符串以null结尾:for(char*inputPtr=input;*inputPtr;++inputPtr){//somecode}请记住,您发

c++ - size_type 和 int 之间的区别

#include#includeusingnamespacestd;intmain(){vectorstudent_marks(20);for(vector::size_typei=0;i>student_marks[i];}return0;}我在某处读到,最好使用size_type代替int。它真的会对实现产生巨大影响吗?使用size_type有什么好处? 最佳答案 vector::size_type保证涵盖vector大小的所有可能值范围.一个int不是。请注意vector::size_type通常与std::size_t相同,

c++ - 将 `unsigned char` 放入 `char`

我想通过移位将一个unsignedchar存储到一个char中。由于这两种数据类型具有相同的长度(在我的机器上为1个字节),我希望以下代码能够工作:#include#include#includeusingnamespacestd;intmain(){printf("%d\n",sizeof(char));printf("%d\n",sizeof(unsignedchar));unsignedchartest=49;chartestchar=(char)(test-127);printf("%x\n",testchar);return0;}但事实并非如此。特别是,我得到了以下输出:11

c++ - 是否已初始化静态 char[] 缓冲区

我在文件范围内有这个:staticcharfoo[256];内存是否在所有平台和构建配置上都初始化为零?(即它是标准的C++)。 最佳答案 Isthememoryinitialisedtozeroonallplatformsandbuildconfigurations?是的,所有非局部变量都是零初始化的。(i.e.isitC++standard)是的。C++113.6.2指定了如何初始化非局部变量。特别是:Variableswithstaticstoragedurationorthreadstoragedurationshallbe