草庐IT

render_template_string

全部标签

c++ - 标准 :forward inside a template class

templateclassBlockingQueue{std::queuecontainer_;templatevoidpush(U&&value){static_assert(std::is_same::type>::value,"Can'tcallpushwithoutthesameparameterastemplateparameter'sclass");container_.push(std::forward(value));}};我希望BlockingQueue::push方法能够处理T类型对象的右值和左值引用,以将其转发到std::queue::push正确的版本。是像上面

c++ - 当我从 char[] 转到 string 时,为什么我的冒号字符消失了?

在我正在处理的旧Windows应用程序中,我需要从环境变量获取路径,然后附加到它以构建文件路径。所以代码看起来像这样:staticstd::stringPathRoot;//Privatevariablestoredinclass'headerfilecharEnvVarValue[1024];if(!GetEnvironmentVariable(L"ENV_ROOT",(LPWSTR)EnvVarValue,1024)){coutENV_ROOT的环境值在Windows系统控制面板中设置为“c:\RootDir”。但是当我运行程序时,我总是以FullFilePath中的字符串结尾,该

c++ - 错误 : ‘template<class> class std::auto_ptr’ is deprecated

我正在使用scons和ubuntu。当我使用'scons'制作一些程序时,会发生错误,例如,src/db/DBTextLoader.cc:296:3:error:‘templateclassstd::auto_ptr’isdeprecated[-Werror=deprecated-declarations]/usr/include/c++/5/bits/unique_ptr.h:49:28:note:declaredheretemplateclassauto_ptr;这是我的命令;$./configuer$sourcesomething.sh$scons其实我也不知道。我已经在搜索这个

c++ - Qt - 获取 "warning: format not a string literal and no format arguments"

在这样的行上不断收到警告qDebug("Anerroroccuredwhiletryingtocreatefolder"+workdir.toAscii());workdir是QString()warning:formatnotastringliteralandnoformatarguments 最佳答案 大概应该是:qDebug("Anerroroccuredwhiletryingtocreatefolder%s",workdir.constData());自qDebug将constchar*作为第一个参数。

C++ - include <string> 错误

我是c++的新手,正在编写教程。我已经完全复制了教程,但在编译时出现此错误:'Stringfilenotfound'对于行#include;有人可以告诉我如何修改吗? 最佳答案 Ok,soIchangedthenameofmyfilefrom.Cto.cppandthisparticularissueseemstohavegone.您似乎找到了解决方案,我添加这个是为了阐明为什么会发生这种情况。一些与IDE集成的编译器会处理.c文件作为C源代码.cpp(或.cc、.c++等)作为C++代码。当你编译.c文件,不包括C++支持,并且使

c++ - 错误 : Expected template-name before '<' token

我正在尝试编译一个实现chain和chainNodes的程序并在以下行(第22行)出现错误:classchain:publiclinearList错误是:Error:expectedtemplate-namebefore'知道为什么会出现这种情况吗?我的代码如下://linkedimplementationofalinearlist//derivesfromabstractclasslinearListjusttomakesure//allmethodsoftheADTareimplemented#ifndefchain_#definechain_#include#include#in

C++11 : Is it possible to give fixed-template-parameted template to varidic-template-template-parameter?

(是的,由于我糟糕的英语,标题很奇怪;我希望有人能改进它。)接听thisquestion,我发现这段代码有效:templateclassA{};templateclassU>classB{};intmain(){Bit_works;}..虽然templateclass和templateclass不相等。我试图弄清楚为什么这是可能的,并观察了N3337standard的[temp.param],但我找不到任何东西。怎么可能? 最佳答案 是的,这是可能的。C++1114.3.3/3特别允许,并提供了一个例子。3Atemplate-arg

c++ - 使用 boost 检查 std::string 是否是有效的 uuid

我想使用boost检查给定的字符串是否是有效的UUID。这是我通过查看boost网站上的文档得出的结论:voidvalidate_uuid(conststd::string&value){try{boost::uuids::string_generatorstringGenerator;(void)stringGenerator(value);}catch(conststd::exception&ex){//...}}但是,这并不总是有效。如果我使用对于有效UUID来说太短的字符串调用该函数,则会按预期抛出异常。但是,如果我使用无效的UUID(例如00000000-0000-0000-

c++ - 我应该使用 operator+= 而不是 operator+ 来连接 std::string 吗?

我经常看到这个结构是有原因的吗:std::stringmyString=someString+"text"+otherString+"moretext";...而不是这个(我很少看到):std::stringmyString;myString+=someString+="text"+=otherString+="moretext";阅读std::stringAPI,在我看来operator+创建了很多临时对象(可能被编译器RVO优化掉了?),而operator+=变体仅append文本。在某些情况下,operator+变体将是可行的方法。但是,当您只需要将文本append到现有的非常量

c++ - string 和 string_view 的索引运算符([])的区别

C++17为我们提供了string_view来优化我们在只需要查看底层字符序列时不必要地分配内存的场景。明智的做法是,您几乎总是可以将conststd::string&替换为std::string_view。考虑以下示例:charfoo(conststd::string&str){returnstr[0];}以上是对std::string的所有值有效的函数。但是,如果我们将其更改为:charfoo(std::string_viewsv){returnsv[0];}我们触发了大小为0的字符串的未定义行为!This最后有一个注释:Unlikestd::basic_string::opera