草庐IT

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 FileSystem3 迭代器转换为 const char*

我正在使用BoostFileSystem3循环遍历目录中的一些文件,我需要将文件名转换为char*以用于另一个库,不幸的是我的C++foo缺失,任何人都可以帮忙吗?intmain(intargc,char*argv[]){pathp(argv[1]);//preadsclearerthanargv[1]inthefollowingcodetry{if(exists(p))//doespactuallyexist?{if(is_regular_file(p))//isparegularfile?coutvec;//storepaths,vecv;//sowecansortthemlate

c++ - double 到 unsigned int/char

我读了here,即:根据C99§6.3.1.4脚注50:Theremainderingoperationperformedwhenavalueofintegertypeisconvertedtounsignedtypeneednotbeperformedwhenavalueofrealfloatingtypeisconvertedtounsignedtype.Thus,therangeofportablerealfloatingvaluesis(−1,Utype_MAX+1).现在,我对以下之间的细微差别感兴趣(这次是针对C++03!):doubled1=257;doubled2=-2

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

java - java函数中static const char *的等价性

我经常在C++中使用这个习语:/*returntype*/foo(/*parameters*/){staticconstchar*bar="Bar";/*somecodehere*/}在内部这被添加到字符串文字表中。这段Java代码是否做类似的事情:/*returntype*/foo(/*parameters*/){finalStringbar="Bar";/*somecodehere*/}还是我无意中引入了效率低下的问题? 最佳答案 字符串在Java中是不可变的。这意味着您不必通过提示让JVM知道它不会更改和优化它。字符串文字被保

c++ - 如何将 'wchar_t *' 转换为 'const char *'

如何将'wchar_t*'转换为'constchar*'?使用C++MFCVS2010。谢谢。 最佳答案 由于问题是关于MFC的,我建议如下:CStringAa="Test";CStringWw=L"Test";a=CStringA(w);w=CStringW(a);我通常需要以下转换:CStringt=_T("Test");//dependsonTCHARtypea=CStringA(t);//doesnotdependonTCHARtypew=CStringW(t);CStringW和CStringA分别有运算符LPCWSTR和

c++ - 未作为最后一个参数传递时模板参数包扣除

考虑以下代码:#include#includetemplatevoidtestfunc(conststd::function&func){}intmain(intargc,char*argv[]){autofunc=[](float,int,char){};autosfunc=static_cast>(func);testfunc(sfunc);return0;}我明确指定类型是因为(https://stackoverflow.com/a/40476083):Whenaparameterpackdoesn'tappearlastintheparameterdeclaration,iti

c++ - “使用”声明为 SFINAE

我可以使用SFINAE(或其他技术)在using声明的同时从模板类派生private吗?为了更好地理解,请参阅下面的代码:#includestructS1{voidf(){std::coutstructD:privateT{usingT::f;//usingT::g;//needthisonlyifTprovidesg()function};intmain(){D().f();//ok.Prints'S1::f'D().f();//ok.Prints'S2::f'D().g();//fail.Butwantstobeokandprints'S2::g'return0;}我怎样才能达到期

C++ 将 char 转换为 const char *

我正在尝试使用beginthreadex创建一个线程,该线程将运行一个以char作为参数的函数。不过,我不擅长C++,而且我不知道如何将char转换为constchar,beginthreadex需要它作为其参数。有没有办法做到这一点?我发现很多关于将char转换为constchar的问题,而不是转换为constchar*。 最佳答案 chara='z';constchar*b=&a;当然,这是在栈上。如果你需要它在堆上,chara='z';constchar*b=newchar(a);

C++ 非类型模板参数 const char*

假设我们有templatestructA{};//staticstorageconstchara[]="asd";constchar*p="asd";这个实例化A{};编译器没问题。这是可以理解的——数组a衰减为指向第一个元素的指针。但是如果我们像这样用p实例化AA{};编译器报错:error:non-typetemplateargumentoftype'char*'isnotaconstantexpression为什么标准不允许指定类型为constchar*的命名变量或只是字符串文字"asd",顺便说一句,它本身是左值,作为模板参数? 最佳答案