c++ stl vector使用

1

using namespace std;	
const std::vector vNames = {"cat","dog","cow"};
const std::vector vfood = {"grass", "banana" };

for (std::vector::const_iterator iterName = vNames.cbegin(); iterName != vNames.cend(); iterName++)
{
	for (std::vector::const_iterator iterfood = vfood.cbegin(); iterfood != vfood.cend(); iterfood++)
	{
		string name = *iterName;
		string food = *iterfood;
		
	}
}

2 找最大值最小值

#include 
#include 
#include 
#include 

std::vector vX;
vX.push_back(1);
vX.push_back(2);
vX.push_back(3);
vX.push_back(7.3);

float max = *max_element(vX.begin(), vX.end());
float min = *min_element(vX.begin(), vX.end());

 

你可能感兴趣的:(c++,stl)