W
wang
Hi all,
I try to store data into map and vector without success.
Data to be stored: a book has several chapters, a chapter has several
sections, a section has many lines.
C++ definition:
map<string, //chapter
map<string, //section
vector<string> //lines
>
> bookData;
This definition does not cause any compilation error. But if I add the
following line, a lot of errors are produced:
((bookData["Chapter 1"])["Section 1.1"]).push_back("This is the first
line.");
My thought is: since bookData is empty, using the subscript "Chapter
1" should add an entry into the map, and the return value should be
the mapped_type, here the sections, which is itself an empty map, and
using the subscript "Section 1.1" should add an entry and return the
lines vector, and using "push_back" should add a line to it. But this
does not work. Could you please give me hint on how to improve this
code to make it work? Many thanks in advance!
kwwang
I try to store data into map and vector without success.
Data to be stored: a book has several chapters, a chapter has several
sections, a section has many lines.
C++ definition:
map<string, //chapter
map<string, //section
vector<string> //lines
>
> bookData;
This definition does not cause any compilation error. But if I add the
following line, a lot of errors are produced:
((bookData["Chapter 1"])["Section 1.1"]).push_back("This is the first
line.");
My thought is: since bookData is empty, using the subscript "Chapter
1" should add an entry into the map, and the return value should be
the mapped_type, here the sections, which is itself an empty map, and
using the subscript "Section 1.1" should add an entry and return the
lines vector, and using "push_back" should add a line to it. But this
does not work. Could you please give me hint on how to improve this
code to make it work? Many thanks in advance!
kwwang