草庐IT

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 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

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++ 将 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",顺便说一句,它本身是左值,作为模板参数? 最佳答案

c++ - const char* 与 C++ 双重翻译问题

我有两个使用同一个库的示例应用程序,它们之间的主要区别在于一个使用qt而另一个应用程序是控制台应用程序。在公共(public)库中,我有这个测试代码:doubletest=0.1;doubletest2=atof("2.13134");doubletest3=atof("1,12345");如果我使用非qt应用程序,则值为:test=0.10000000000001test2=2.1323399999999999998test3=1//Thisistheexpectedresultusinga','asdelimitationcharacter但是对于qt应用程序:test=0.100

c++ - std::array<char, N> 的大小是多少?

这个问题在这里已经有了答案:Isthesizeofstd::arraydefinedbystandard(1个回答)关闭8年前。C++标准对sizeof(std::array)有何规定?应该是(对于某个常量N)?在commenttoadifferentquestion中,有人提到std::array并不总是“堆栈分配”。该评论是对另一条评论的回应,该评论推测为std::array设置了一个太大的常量。声明为局部变量的变量可能会由于“堆栈分配”变量的资源不足而导致程序中止。我假设后续评论意味着std::array是可能的以某种方式切换到动态分配模式。我可以想象,可能会有某种SFINAE可