摘要: 最近在练习使用STL中德各种容器,像vector,map,set之类的。然后在使用vector的时候,无意间遇到了一个很二逼的问题。主要是这样的,请看源码(C++)://错误的写法: #include "stdafx.h" #include #include #include using namespace std; int main() { vector MyVector; //这里是没有申明数量的,而下面用的下标访问,会出现错误 for(int i=0;i>a; return 0; } //改进的方法一 #include #include #include ... 阅读全文
posted @ 2013-07-27 09:58 旧事乡里人 阅读(219) 评论(0) 推荐(0) 编辑
摘要: 本文主要是使用了STL中德map和set两个容器,使用了它们本身的一些功能函数(包括迭代器),介绍了它们的基本使用方式,是一个使用熟悉的过程。map的基本使用:#include "stdafx.h" #include #include #include #include #include using namespace std; int main() { //定义map对象 map myMap; myMap["jack"]=98.5; myMap["bomi"]=98.0; myMap["Kate"]=97.6; 阅读全文
posted @ 2013-07-27 09:51 旧事乡里人 阅读(202) 评论(0) 推荐(0) 编辑
摘要: 以下是使用STL中map类型,对类型的转换示例,主要可以解决的问题,也就是一般的类型之间的相互转换,可以较好的解决相关的问题。以下是C++源码,比较简短,容易理解的。#include "stdafx.h" #include #include #include #include #include using namespace std; int main() { //定义map对象,将字符映射成为数字 map cTi; for(int i=0;i iTc; for(int i=0;i>k; return 0; } 一些细节的地方说明,请看源码中的注释... 阅读全文
posted @ 2013-07-27 09:43 旧事乡里人 阅读(220) 评论(0) 推荐(0) 编辑