草庐IT

-std=gnu99

全部标签

.net - 如何将 System::String^ 转换为 std::string?

所以我在clr中工作,在VisualC++中创建.netdll。我相信这样的代码:staticboolInitFile(System::String^fileName,System::String^container){returnenc.InitFile(std::string(fileName),std::string(container));}有编码器通常resivesstd::string。但是如果我从std::string和C2440中删除参数,编译器(visualstudio)会给我C2664错误,这通常是相同的。VS告诉我它不能将System::String^转换为std

c++ - 如何合并 2 个 std::maps,并在第 3 个映射中输出结果

编辑原始问题,因为我想问有关std::map的问题,而不是std::vector。我的错。对不起。我的数据实际上在2个std::map中。我想将这两张map合并成第三张map。我的第一张和第二张map包含具有相同键的条目。所以我也想将这些键下的数据合并到我生成的第三张map中。因此,如果我使用std::merge,我是否会丢失第一个或第二个映射公共(public)条目中的数据?正如我所提到的,两个map中都有共同的数据(值)? 最佳答案 顺序容器的信息如果vector(或其他顺序容器,如list或deque)已排序,则可以使用std

c++ - 关于将 std::less 和 std::greater 与 std::sort 一起使用的困惑

在C中,排序通常如下例所示实现:#includevoidSort(int*arr,intn,bool(*cmp)(int,int)){for(inti=0;ib;}//greaterintdescending(inta,intb){returna所以我写了一些源代码,如下例所示,期望得到相同的结果:#include#include//forsort#include//forless&greaterusingnamespacestd;boolgt(inta,intb){returna>b;}//greaterboolls(inta,intb){returnag;//a>blessl;//

c++ - 为什么 std::remove 不能与 std::set 一起使用?

以下代码:#include#include#includestd::sets;intmain(){s.insert(1);s.insert(2);std::remove(s.begin(),s.end(),1);}不能用gcc4.7.2编译:$LANG=Cg++test.cppInfileincludedfrom/usr/include/c++/4.7/algorithm:63:0,fromtest.cpp:3:/usr/include/c++/4.7/bits/stl_algo.h:Ininstantiationof'_FIterstd::remove(_FIter,_FIter,c

c++ - 类指针 vector 上的 std::sort()

我有一个类指针vectorstd::vectorlistSquares.我想用类的属性之一作为键对它进行排序。这就是我正在做的boolcompById(Square*a,Square*b){returna->getId()getId();}std::sort(listSquares.begin(),listSquares.end(),compById)但是编译器说:错误:没有匹配函数来调用'sort(std::vector::iterator,std::vector::iterator,)'我做错了什么? 最佳答案 为了使用comp

c++ - 为什么 std::vector 使用 move 构造函数,尽管声明为 noexcept(false)

无论我在互联网上的什么地方阅读,强烈建议如果我希望我的类(class)与std::vector一起工作(即std使用我类(class)的move语义::vector)我应该将构造函数delcaremove为'noexcept'(或noexcept(true))。为什么std::vector使用它,即使我将它标记为noexcept(false)作为实验?#include#includeusingstd::cout;structT{T(){coutt_vec;t_vec.push_back(T());}输出:T()T(T&&)~T()~T()为什么?我做错了什么?在gcc4.8.2上编译,

C++ std::istream readsome 不读取任何内容

这就像readsome甚至没有阅读。返回0并且不读取任何字符。这里有什么问题?#include#includeintmain(){std::fstreamstream("list.cpp",std::ios::in);if(stream.good()||!stream.bad()||stream.is_open()){std::cout输出:嗯,流看起来不错。0:大号 最佳答案 咨询areference,Thebehaviorofthisfunctionishighlyimplementation-specific.Forexamp

c++ - 你能重用 move 的 std::string 吗?

这个问题在这里已经有了答案:Reusingamovedcontainer?(3个答案)关闭8年前。给出这个例子:std::vectorsplit(conststd::string&str){std::vectorresult;std::stringcurr;for(autoc:str){if(c==DELIMITER){result.push_back(std::move(curr));//ATTENTIONHERE!}else{curr.push_back(c);}}result.push_back(std::move(curr));returnresult;}我可以重用currst

c++ - 从 CFURLRef 或 CFStringRef 转换为 std::string

如何将CFURLRef转换为C++std::string?我还可以通过以下方式将CFURLRef转换为CFStringRef:CFStringRefCFURLGetString(CFURLRefanURL);但是现在我遇到了同样的问题。如何将CFStringRef转换为std::string? 最佳答案 CFStringRefistollfreebridged到NSString对象,所以如果您以任何方式使用Cocoa或ObjectiveC,转换都非常简单:NSString*foo=(NSString*)yourOriginalCFS

c++ - std::unique_ptr 是 RAII 的应用吗?

这是对它的准确描述吗?有道理吗?您是否保证在unique_ptr超出范围之前它指向的对象不会被删除[即使您没有使用unique_ptr]? 最佳答案 是的,std::unique_ptr遵循RAII设计原则。不,std::unique_ptr不会阻止其他代码做一些愚蠢的事情,比如在属于unique_ptr的指针上调用delete>。unique_ptr本身将在其拥有的对象上调用deleter1,当出现以下任一情况时:超出范围或unique_ptr被重新分配(通过operator=或reset)以指向不同的对象还可以通过移动到不同的智