草庐IT

application-end

全部标签

c++ - 为什么在 std::copy 期间使用 std::back_inserter 而不是 end()?

我见过std::copy()使用std::back_inserter但我使用了std::end()并且两者都有效.我的问题是,如果std::end()工作正常,为什么还需要std::back_inserter?#include#include#include#includeusingnamespacestd;intmain(){//Declaringfirstcontainervectorv1={1,2,3};//Declaringsecondcontainerfor//copyingvaluesvectorv2={4,5,6};//Usingstd::back_inserterins

c++ - 为具有 "end"成员变量的类型启用基于范围的 for

我正在使用avectortype来自C库,看起来类似于structVec{int*stor_begin;int*stor_end;int*end;};我试图通过创建免费的begin()和end()函数为这种类型启用基于范围的for循环,但是我从clang得到了这个错误:error:rangetype'igraph_vector_int_t'has'end'memberbutno'begin'member有没有办法(使用C++11)为这种类型(我不能直接修改)启用基于范围的for循环?这是一个演示问题的最小示例://NoproblemswithFoostructFoo{int*fooBe

c++ - 开发人员无法执行 .exe 错误 193 : %1 not a valid win32 application

所以我试图像往常一样测试运行我的开发c++,它说无法执行location/name.exe错误193:%1不是有效的win32应用程序。我还没有将编译器用于任何复杂的东西。#include#include#definePI3.14intmain(){intr=3;floatarea=PI*pow(r,2);printf("theareaofthecircleis%f",area);return0;}我正在使用Devc++GCC(MinGW)编译器。它编译正确,但是当我尝试运行时,它收到此错误消息无法执行“C:\Users\SIMJONESNIGLTD\Desktop\clanguage

C++ 控制台 Application1.exe 已触发断点

当我尝试设置时cub.SetArray(cube);我得到一个错误ConsoleApplication1.exehastriggeredabreakpoint我做错了什么?当我尝试调试cub->cubesarray时,我得到大小-842150451。我不明白为什么。这是我的所有代码classCube{public:staticconstintChange_ARRAY=5;private:stringcolor;intsize;int*walls;intn;//currentsizeofarrayintmaximumsize;//maximumsizeofarrayvoidIncreas

c++ - 使用 std::vector.erase(begin(), end()) 或 std::vector.erase(begin(), begin()) 安全吗?

我想处理vector中的元素一段时间。为了优化这一点,我不想在处理项目时删除它,而是在最后删除所有已处理的项目。vector::iteratorit;for(it=items.begin();it!=items.end();++it){DoSomething(*it);if(TimeIsUp()){break;}}items.erase(items.begin(),it);当it==items.end()时使用erase是否安全?在文档中说erase()将删除[first,last)并且这应该是安全的,但我想确定。编辑:使用std::vector.erase(begin(),begin

c++ - 如何正确的va_end?

#includeusingnamespacestd;voiddo_something(va_listnumbers,intcount){//^//ShouldIcallthisbyreferencehere?Imean,va_list&numbers?//...stuffva_end(numbers);}voidsetList(intcount,...){va_listnumbers;va_start(numbers,count);do_something(numbers,count);}intmain(){setList(2,0,1);return0;}当将va_list传给另一个函

c++ - 为什么在查找元素时需要使用 set.find(x) != set.end() 。

我想知道当我使用*(set.find(x))==x时出了什么问题而不是set.find(x)!=set.end()。它通常有效,但在尝试在Hackerrank上提问时(问题:link)。此代码为所有测试用例提供CA:intmain(){/*Enteryourcodehere.ReadinputfromSTDIN.PrintoutputtoSTDOUT*/sets;intn,x,y;cin>>n;while(n--){cin>>y>>x;if(y==1)s.insert(x);elseif(y==2)s.erase(x);else{set::iteratorit=s.find(x);if

c++ - 为什么我不能将 std::begin/std::end 与 int(*p)[3] 一起使用,而我可以与 int(&p)[3] 一起使用?

这个有效:voidfoo(int(&a)[3]){autoibegin=begin(a);autoebegin=end(a);}虽然这不是:voidfoo(int(*a)[3]){autoibegin=begin(a);autoebegin=end(a);}我认为int(&a)[3]和int(*a)[3]是同一个意思! 最佳答案 您的代码类似于:voidfoo(vector&a){autoibegin=begin(a);autoebegin=end(a);}voidfoo(vector*a){autoibegin=begin(a);

c++ - Qt5 QtQuick 2.0(Qt Quick Application) 在一个窗口中切换 View (qml文件)

在传统的Qt(QWidget)中,我有一个QMainWindow和一些动态创建的带有内容的QWidgets,我将它们更改为在主窗口中看到的。当我有几个qml文件并且我希望能够在例如单击按钮时在它们之间切换时,有什么方法可以实现。 最佳答案 解决这个问题至少有3种选择:您可以使用为此目的准备好的组件StackView.重点是您将同时创建2个组件,并且您可以通过单击按钮来更改它们。例子:importQtQuick2.12importQtQuick.Controls2.5ApplicationWindow{id:windowvisible

c++ - eclipse c++ 中的 "control reaches end of non-void function"警告但没有编译或运行时错误

这是我的代码:Composer&Database::GetComposer(stringin_last_name){for(inti=0;i想法是遍历Composer对象数组并返回对其last_name字段与“in_last_name”匹配的对象的引用。我明白警告在告诉我什么,即函数可能不会返回任何内容(如果用户提供了无效的姓氏)。我的问题是,我怎样才能避免这种情况?我尝试在for循环之后添加“return0”和“returnNULL”,但它无法编译。如果此方法什么也没找到,是否应该抛出异常? 最佳答案 您的函数被声明为返回一个Co