vector<vector<string>> clothes; ์ push_back() ๊ฐ๋ฅํ ๊ฒ์,
vector <string>kind_name1;
vector <string>kind_name2;
vector <string>kind_name3;
๋ฑ์ vector<string>ํ ๋ฟ์ด๋ค.
๊ฐ๋ น, kind_name1,kind_name2,kind_name3์ ๊ฐ๊ฐ ์ ๋นํ string์ push_back()ํด์ฃผ๊ณ
์ด๊ฒ๋ค์ ๋ vector<vector> clothes; ์ push_back() ํ๋ค๋ฉด...
kind_name1.push_back("yellowhat");
kind_name1.push_back("headgear");
kind_name2.push_back("bluesunglasses");
kind_name2.push_back("eyewear");
kind_name3.push_back("green_turban");
kind_name3.push_back("headgear");
์ต์ข ์ ์ธ clothes์ ๋ฐฐ์ด ์ํ๋ ์ด๋ ๊ฒ ๋๋ค.
kind_name1 | kind_name2 | kind_name3 |
์๋ฐํ ์ธ๋ฑ์ค๋ฅผ ๋ฐ์ง์๋ฉด ์ด๋ฐ ์ํ
[0][0] [0][1] | [1][0] [1][1] | [2][0] [2][1] |
[0][0] | [0][1] | [1][0] | [1][1] | [2][0] | [2][1] |
์ธ๋ฑ์ค์ ๊ฐ๋ค์ ๋ณด์๋ฉด ์ด๋ฐ ์ํ
yellowhat | headgear | bluesunglasses | eyewear | green_turban | headgear |
์๋๋ ์์ ์ค๋ช ์ ์์ฑํ ์ฝ๋์ด๋ค.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void)
{
vector<string>kind_name1;
vector<string>kind_name2;
vector<string>kind_name3;
vector<vector<string>> clothes;
kind_name1.push_back("yellowhat");
kind_name1.push_back("headgear");
kind_name2.push_back("bluesunglasses");
kind_name2.push_back("eyewear");
kind_name3.push_back("green_turban");
kind_name3.push_back("headgear");
clothes.push_back(kind_name1);
clothes.push_back(kind_name2);
clothes.push_back(kind_name3);
for (int i = 0; i < clothes.size(); i++)
{
for (int j = 0; j < clothes[i].size(); j++)
{
cout <<clothes[i][j]<<' ';
}
cout <<'\n';
}
return 0;
}
์ถ๋ ฅ๊ฒฐ๊ณผ
yellowhat headgear
bluesunglasses eyewear
green_turban headgear
'C++ > c++' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[STL] key ์ค๋ณต๊ฐ๋ฅํ multimap๊ณผ make_pair ์กฐํฉ (0) | 2022.01.05 |
---|---|
[STL] unordered_map๊ณผ make_pair ๊ฐ์ด ์ฐ๊ธฐ (0) | 2022.01.04 |
[STL] multimap์ ํ์ ๋ฐฉ๋ฒ (0) | 2022.01.04 |
c++ vector /pair / sort ์ฌ์ฉ ์์ (0) | 2021.11.17 |
[c++] std::array / try catch / auto element ์ฐ์ต ์์ (0) | 2021.09.21 |