Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I put items into a const vector?

Tags:

c++

vector

I've been trying a bunch of different ways, but I can't figure it out. The declaration that I was given is:

const std::vector<std::string>&,

I've been trying to do this:

gradeReported.push_back(firstEntry);

I keep getting an error. I am pretty sure it has something to do with the const nature of the vector. Help would be appreciated!

like image 407
DangerMoose Avatar asked Dec 09 '22 01:12

DangerMoose


1 Answers

You don't. If it's const, it cannot be modified. You need to make a copy or take it by non-const reference.

like image 127
Cat Plus Plus Avatar answered Mar 29 '23 12:03

Cat Plus Plus