您的位置:首页 > 其它

STL vector的使用(三)遍历

2015-08-25 09:09 232 查看
一. vector的遍历总类:

1. 未用名字空间,使用vector 进行遍历:



for(std::vector<std::string>::size_type index = 0; index < vect.size();index++)
	{
		std::cout << vect[index]   << std::endl;
	}


2. 使用名字空间,使用vector进行遍历:



for(int index = 0; index < vect.size();index++)
	{
		cout << vect[index]   << endl;
	}


3. 利用迭代器,对vector进行遍历:



vector<string>::iterator it = vect.begin();

	for(;it != vect.end();it++)
	{
		cout << *it  << endl;
	}




内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: