qfedu-cpp-level/day10/stl_list_demo/d1.cpp

28 lines
482 B
C++
Raw Permalink Normal View History

2023-08-14 17:20:39 +08:00
#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
template <typename T>
void print(const list<T> &lst)
{
for (typename list<T>::const_iterator it = lst.begin(); it != lst.end(); ++it)
cout << *it << ' ';
cout << endl;
}
int main()
{
list<int> lst1(6, 5); // 6 个 5
print(lst1);
string s1 = "abcdefg";
// 将 string 字符串转换为 list
list<char> lst2(s1.begin(), s1.end());
print(lst2);
return 0;
}