G
G
Gokilla2018-04-15 19:13:38
C++ / C#
Gokilla, 2018-04-15 19:13:38

Error with c++ vector?

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
struct Customer
{
  int customerID;
  std::string salutation;
  std::string dateOfBirth;
  std::string state;
  std::string creationDate;
};
struct Item
{
  int itemID;
  std::string size;
  std::string color;
  int manufacturerID;
  double price;
};
struct Order
{
  int orderItemID;
  std::string orderDate;
  std::string deliveryDate;
  Customer *customer;
  Item *item;
};

int main()
{
  std::string str;
  std::ifstream file("C:\\Users\\User\\Desktop\\инт сис\\04\\orders_class.txt", std::ios::in);
  std::vector<Order>*vec = new std::vector<Order>();
  while (!file.eof())
  {
    getline(file, str);
    //std::cout << str << std::endl;
    vec->push_back(new std::vector<Order>());
  };
  file.close();
  system("pause");
  return 0;
}

ошибка там где vec->push_back(new std::vector<Order>());

Серьезность	Код	Описание	Проект	Файл	Строка	Состояние подавления
Ошибка	C2664	"void std::vector<Order,std::allocator<_Ty>>::push_back(const Order &)": невозможно преобразовать аргумент 1 из "std::vector<Order,std::allocator<_Ty>> *" в "Order &&"	analytics	c:\users\user\documents\visual studio 2015\projects\main.cpp	39

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Gokilla, 2018-04-15
@Gokilla

Decided like this:

std::vector<Order*>*vec = new std::vector<Order*>();

    vec->push_back(new Order());

M
maaGames, 2018-04-15
@maaGames

std::vector*vec = new std::vector();
replace with
std::vector*vec = new std::vector();
either
vec->push_back(new std::vector());
on
vec->push_back(std::vector());
whatever you want to get. In general, everything is written in the error message.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question