P
P
PythonBeginner202018-11-13 00:14:28
C++ / C#
PythonBeginner20, 2018-11-13 00:14:28

How to change vector inside map c++?

Hello, I'm interested in solving the following problem. I have a map> and I need to access a vector by its key and resize it. How can I do it?
map<string, vector<string>> SOURCE;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman, 2018-11-13
@PythonBeginner20

map<string, vector<string>> mymap;
string key = "asdf";

auto elem {mymap.find(key)};
if(elem != mymap.end())
{
  //...
  elem->second.resize(42);
}

...
в С++17 можно еще проще/по-другому.

J
jcmvbkbc, 2018-11-13
@jcmvbkbc

I need to access a vector by its key and resize it. How can I do it?
SOURCE["key"].resize(new_size);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question