代码:
#include <iostream>
#include <list>
#include <string>
#include <map>
using namespace std;
int main(int argc, const char * argv[]) {
list<string> myList;
myList.push_back("shunquan");
myList.push_back("james");
for (list<string>::iterator it = myList.begin(); it!=myList.end(); it++) {
cout<<*it<<"\n";
}
map<string,string> m;
m.insert(pair<string, string>("hello", "hello shunquan"));
m.insert(pair<string, string>("name","shunquan"));
cout <<m.at("name")<<"\n";
cout <<m["hello"]<<"\n";
return 0;
}
1. list string map 使用前要include 相应的库文件
2. 使用 using namespace std 避免重复输入 std::
3. list 是如何定义的,如何赋值的,如何输出的
4. map 如何定义,如何赋值,如何输出(2种方式)
本文介绍了C++中list和map的基本用法,包括如何定义、赋值及输出。通过实例展示了list容器的元素添加与迭代输出,以及map的插入与访问操作。
4273

被折叠的 条评论
为什么被折叠?



