草庐IT

CHAR_LENGTH

全部标签

c++ - 如何从 char* 转换为 T*?

这个问题在这里已经有了答案:关闭11年前。PossibleDuplicate:C++Whenshouldweprefertouseatwochainedstatic_castoverreinterpret_cast哪个更好?static_cast(static_cast(buffer));或reinterpret_cast(buffer);其中buffer是char*(包含T类型值的内存块)。

c++ - 从 ‘void’ 到非标量类型的转换‘std::pair<std::basic_string<char, std::char_traits<char>

我在电子表格obj中有一堆对:std::stack>undoStack;我正在尝试弹出堆栈并将其分配给另一对:std::pairchange=spreadsheets.at(i).undoStack.pop();我收到这个错误:error:conversionfrom‘void’tonon-scalartype‘std::pair,std::allocator>,std::basic_string,std::allocator>>’requested这里出了什么问题? 最佳答案 stack::pop()返回void但您正试图将其分配

c++ - 在 C++ 中命名 int 或 char 变量时, "n"或 "ch"前缀是常见前缀吗?

我目前正在浏览learncpp.com的C++教程,我看到他们的变量命名趋势是使用“n”前缀(即intnValue)和“ch”前缀为char变量(即charchOperation)命名int变量。这是不是我现在应该养成的行业普遍现象? 最佳答案 Isthissomethingthatiscommonplaceintheindustry?由于对somewhatmoreusefulconvention的误解,这种做法在二十或三十年前的Microsoft某些部门很常见。公司其他部分使用(标记变量表明它们的用途,在弱类型语言中,这有助于避免

c++ - operator const char* 以奇怪的方式覆盖(?)我的另一个变量

#include#includeclassVector{double_x;double_y;public:Vector(doublex,doubley):_x(x),_y(y){}doublegetX(){return_x;}doublegetY(){return_y;}operatorconstchar*(){std::ostringstreamos;os这个程序的输出:$./a.outVectorw1(1.1,2.2)Vectorw2(3.3,4.4)Vector(3.3,4.4)Vector(3.3,4.4)我不明白为什么会得到输出。似乎是“constchar*n2=w2;”覆盖

c++ - 如何让一个 char* 指向一个 char[]?

我想知道是否有办法让char*指向char数组的内容,这样我就可以修改char*跨功能。例如voidtoup(char*c){chararray[sizeof(c)];for(intx;x尝试使array=char*似乎不起作用。是否可以让char*指向char数组? 最佳答案 Isitpossibletomakethechar*pointtothechararray?是的。而不是:intmain(){char*c="Hello";toup(c);}使用:intmain(){charc[]="Hello";toup(c);}char

c++ - std::make_pair:无法将 'ch'(类型 'char')转换为类型 'char&&'

这个问题在这里已经有了答案:C++11make_pairwithspecifiedtemplateparametersdoesn'tcompile(1个回答)关闭9年前。以下代码有什么问题:#include#include#include#include#includeintmain(){std::vector>vec;for(unsignedi=0;i(ch,number))!=vec.end());std::cout(ch,number));}}它确实可以很好地编译:g++test.cxx但失败了:$g++-std=c++11test.cxx/tmptest.cxx:Infunct

c++ - const char * 和 char *

我明白了char*s="HelloWorld!";存储在只读内存中,不能通过指针修改字符串文字。这和有什么不同constchar*s="HelloWorld!";另外'string'的类型是char*还是constchar*? 最佳答案 区别在于后者合法,前者不合法。这是在C++11中所做的更改。形式上,"HelloWorld!"的类型为constchar[13];它可以转换为constchar*。在过去,它的类型可能是char[13],可以转换为char*。C++通过添加const更改了数组的类型,但保留了对char*的转换,以便

c++ - 为什么C++11中signed char的范围是-127到127?

这个问题在这里已经有了答案:Doestherangeforintegervaluesofachardependonimplementation?(5个答案)关闭4年前。我正在通读BjarneStroustrup的《C++编程语言第4版》,但我无法完全理解第141页中提到的以下段落。Eachcharacterhasanintegervalueinthecharactersetusedbytheimplementation.Forexample,thevalueof'b'is98intheASCIIcharacterset.Hereisaloopthatoutputsthetheinteg

c++ - 通过 "\0"而不是 memset() 批量初始化 char 数组

通常由memset初始化的字符数组。我在我的项目代码中发现了由"\0"初始化的char数组。我还编译并检查了,它工作正常。我的问题是这是批量初始化char数组的正确方法吗?例如:chara[20]="\0";printf("%s",a); 最佳答案 是的,这是正确的方法之一。对于c引用C11,第6.7.9章Iftherearefewerinitializersinabrace-enclosedlistthanthereareelementsormembersofanaggregate,orfewercharactersinastri

c++ - 如何将 LPCWSTR 转换为 const char *?

如何将LPCWSTR转换为constchar*?谢谢 最佳答案 使用WideCharToMultiByte功能。请注意,LPCWSTR与constwchar_t*相同,因此如果您在整个应用程序中处理宽字符数据,则可能不需要在全部。 关于c++-如何将LPCWSTR转换为constchar*?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4542521/