@StarSky
2017-06-18T08:27:05.000000Z
字数 1272
阅读 1133
工作日记
C++
initial vector iter in the loop
attention: const_iterator
for (std::vector<int>::const_iterator it = vector.begin(); it != vector.end(); it++)
for(std::vector<int>::const_iterator i = (*it).begin();i != (*it).end();i++)
cout << *i << ' ';
vector
vector.swap(vector_tmp);
In the beginning,I just wanna to clear the vector use vector.clear()
,after exploding on the web, I noticed that vector.swap(vector_temp)
is a better operation that It not only clear the data but also allocate the memory.
a.insert(a.end(), b.begin(), b.end());
a.insert(std::end(a), std::begin(b), std::end(b));
Recently, I found a interesting method to return different data type with the help of struct.
/*
* define multi data struct
* */
struct infectedListInfo{
vector<vector<Point> \*>\* infectedOutList;
vector<Vec4i>* hierarchyList;
int y_range[2];
};
PS: Attention:
everytime you define the struct, It's nameSpace should be signed before the struct name.(became It's only use in your nameSpace, not global)
https://stackoverflow.com/questions/26415054/return-type-out-of-line-definition-differs-from-that-in-the-declaration
ref:
swap vector
http://www.cplusplus.com/reference/vector/vector/swap/
extend vector
https://stackoverflow.com/questions/313432/c-extend-a-vector-with-another-vector
how to implement a multi return.
http://blog.csdn.net/supreme42/article/details/7636475