草庐IT

LCD_write_chinese_string

全部标签

c++ - 为什么 "initializer-string for array of chars is too long"在 C 中编译良好而不在 C++ 中编译?

以下程序在C中编译正常但有警告,但在C++中编译失败。为什么?这是什么原因?#includeintmain(void){chara[5]="Hello";a[0]='y';puts(a);for(inti=0;i警告:Warning:[Error]initializer-stringforarrayofcharsistoolong[-fpermissive]enabledbydefault但如果程序被编译为C++程序,则C++编译器会给出以下错误:[Error]initializer-stringforarrayofcharsistoolong[-fpermissive]我正在使用GC

c++ - 错误 : no matching function for call to ‘std::vector<std::__cxx11::basic_string<char>>::push_back(int&)’

我是C++的新手。当我运行我的代码时出现此错误:(BigSorting.cpp:Infunction‘intmain(int,constchar**)’:BigSorting.cpp:13:22:error:nomatchingfunctionforcallto‘std::vector>::push_back(int&)’v.push_back(m);^Infileincludedfrom/usr/include/c++/8.1.1/vector:64,fromBigSorting.cpp:2:/usr/include/c++/8.1.1/bits/stl_vector.h:1074:

c++ - boost::asio::async_write() 与 boost::asio::write()

在将数据缓冲区传输到线路上所花费的时间方面是否有任何优势如果你使用boost::asio::write(m_socket,asio::buffer(dataOut_,len),asio::transfer_all());代替boost::asio::async_write(m_socket,boost::asio::buffer(hbs,sizeof(hbs)),boost::bind(&Client::handle_pulse,this,boost::asio::placeholders::error,boost::asio::placeholders::bytes_transfer

C++11 内部 std::string 表示 (libstdc++)

std::string在c++11(libstdc++)中是如何内部表示的?在深入研究实现时,我发现:/*Astringlookslikethis:**[_Rep]*_M_length*[basic_string]_M_capacity*_M_dataplus_M_refcount*_M_p---------------->unnamedarrayofchar_type**Wherethe_M_ppointstothefirstcharacterinthestring,and*youcastittoapointer-to-_Repandsubtract1togeta*pointerto

c++ - 在库的公共(public) API 中从 std::string、std::ostream 等过渡

对于具有相同二进制文件的多个工具链之间的API/ABI兼容性,它是wellknownthatSTL容器、std::string和其他标准库类(如iostreams)在公共(public)header中禁止。(异常(exception)情况是,如果一个人为每个版本的受支持工具链分发一个构建;一个人提供没有二进制文件的源代码供最终用户编译,这在当前情况下不是首选选项;或者一个人内联转换为其他容器,以便不同的std实现不会被库吸收。)如果一个人已经有一个不遵循此规则的已发布库API(请friend),那么最好的前进道路是什么,同时保持尽可能多的向后兼容性,并尽可能地支持编译时中断'吨?我需要

c++ - std::string 类继承和繁琐的 C++ 重载解析

我需要扩展std::basic_string来处理路径字符串和不同的operator+:#includetemplateclasspath_basic_string:publicstd::basic_string{public:usingbase_type=std::basic_string;path_basic_string()=default;path_basic_string(constpath_basic_string&)=default;path_basic_string&operator=(constpath_basic_string&)=default;path_basi

c++ - 如何用 vstring 替换 std::string?

我最近了解到,几年前库libstdc++包含vstring(也称为versa_string),它提供与std::相同的功能:string,但显然更符合C++标准。我曾尝试使用vstring来替代std::string,但我发现没有简单的方法来做到这一点。是否有一种简单的方法可以在不更改libstdc++源的情况下将std::string替换为vstring?我可以用别名替换代码中对std::string的所有使用,如以下list所示。然而,这种方法的问题是,std::string也在某些地方内部使用,例如在std::ostringstream中。这意味着语句std::ostringst

c++ - 莱克斯/柔性 :Regular expression for string literals in C/C++?

我看这里ANSICgrammar.本页包含大量用于ANSIC的Lex/Flex正则表达式。在理解字符串文字的正则表达式时遇到问题。他们提到正则表达式为\"(\\.|[^\\"])*\"据我所知,\"用于双引号,\\用于转义字符,.用于任何字符,除了escapecharacter和*为零次或多次。[^\\"]表示除\、"之外的字符。所以,在我看来,正则表达式应该是\"(\\.)*\"。你能给出一些上面的正则表达式会失败的字符串吗?或为什么他们使用了[^\\"]? 最佳答案 正则表达式\"(\\.)*\"您建议的匹配字符串由\组成符号与

c++ - 声明硬编码 std::string 会导致缓冲区溢出

我的程序中有以下行会导致运行时警告:if(!is_directory("C:\\NGFMS_Debug\\Files")&&!create_directories("C:\\NGFMS_Debug\\Files"))警告的文本​​是这样的:“XXX.exe中发生了缓冲区溢出,它破坏了程序的内部状态。”警告出现在对“is_directory(...)”的调用中。我猜字符串的空间没有分配,但我认为这样的语法是合法的。is_directory函数是boost/filesystem.hpp的一部分,我正在使用以下命名空间:usingnamespaceboost;usingnamespacebo

c++ - 如何在 C++11 中将 u32string 转换为 int?

我们如何在C++11中将u32string转换为int?另外,我应该使用什么方法将此类字符串的一部分转换为int-让开始和结束迭代器可用?我试过:u32stringtest=U"14";cout但它抛出:candidatefunctionnotviable:noknownconversionfrom'constchar32_t*'to'constchar*'for1stargumentexternintatoi(__constchar*__nptr) 最佳答案 #include//wstring_convert#include//c