일상 코딩
[C++/CPP] 16.02. STL iterator, 반복자 본문
728x90
C++ 온라인 컴파일러 사이트
- https://replit.com/~
- https://www.onlinegdb.com/online_c++_compiler
- https://cpp.sh/
- https://www.tutorialspoint.com/compile_cpp_online.php
#include<iostream>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
int main()
{
vector<int> container;
for (int i = 0; i < 10; ++i)
container.push_back(i);
{
// vector<int>::iterator
vector<int>::const_iterator itr;
itr = container.begin();
while (itr != container.end())
{
cout << *itr << " ";
++itr;
}
cout << endl;
}
{
for (auto itr = container.begin(); itr != container.end(); ++itr)
{
cout << *itr << " ";
}
cout << endl;
}
{
for(auto & e : container)
cout << e << " ";
cout << endl;
}
{
list<int> container;
for (int i = 0; i < 10; ++i)
container.push_back(i);
for (auto itr = container.begin(); itr != container.end(); ++itr)
cout << *itr << " ";
cout << endl;
for(auto & e : container)
cout << e << " ";
cout << endl;
}
{
set<int> container;
for (int i = 0; i < 10; ++i)
container.insert(i);
for (auto itr = container.begin(); itr != container.end(); ++itr)
cout << *itr << " ";
cout << endl;
for(auto & e : container)
cout << e << " ";
cout << endl;
}
{
map<int, char> container;
for (int i = 0; i < 10; ++i)
container.insert(make_pair(i, char(i + 65)));
for (auto itr = container.begin(); itr != container.end(); ++itr)
{
cout << itr->first;
cout << ":";
cout << itr->second;
cout << " ";
}
cout << endl;
for(auto & e : container)
{
cout << e.first;
cout << ":";
cout << e.second;
cout << " ";
}
cout << endl;
}
return 0;
}
728x90
'C++ > 따배C++ 16강 STL' 카테고리의 다른 글
[C++/CPP] 16.03. STL algorithm (0) | 2022.01.05 |
---|---|
[C++/CPP] 16.01. Standard Template Libraries, containers (0) | 2022.01.02 |