相关疑难解决方法(0)

c ++在已知位置插入向量

我希望在已知位置插入c ++向量.我知道c ++库有一个insert()函数,它接受一个位置和要插入的对象,但位置类型是一个迭代器.我想插入到矢量中,就像我将使用特定索引插入到数组中一样.

c++ stl insert vector

18
推荐指数
3
解决办法
4万
查看次数

需要"一个"对象,如何使用"新"

我写;

Element element=new Element;
Run Code Online (Sandbox Code Playgroud)

我收到了错误;

homework.cpp: In function 'int main(int, char**)':
homework.cpp:227:29: error: conversion from 'Element*' to non-scalar type 'Element' requested

*** 1 errors, 0 warnings
Run Code Online (Sandbox Code Playgroud)

我不想要指针或元素数组,

我应该写一下Element *element= new Element;.有人解释一下吗?

编辑:

元素类:

class Element{
  public:
      Element():exists(false){};

      std::string name;
      std::string full_path_name;
      ElementType element_type;
      long element_size;
      bool exists;

  };
Run Code Online (Sandbox Code Playgroud)

c++ new-operator

-2
推荐指数
1
解决办法
114
查看次数

标签 统计

c++ ×2

insert ×1

new-operator ×1

stl ×1

vector ×1