STL操作注意事项
摘要:1.无符号和有符号整型的问题在C/C++中无符号整型与整型进行比较时,会自动将整型转换为无符号整型,所以如果整型值是负数,那么结果可能不是你预期的那样。比如: int a = -1; unsigned int b = 3; a < b的结果将会是false。这在对STL中容器的size()时尤其重要,因为.size()实际上返回的是个无符号型数。尤其如果进行 if(a >= vectorX.size() - 1) {vectorX.push_back(0);}之类的操作时,一定要注意了,因为vectorX.size()是从0开始,这样,这句话永远也不成立,在执行循环时,vector
阅读全文
posted @
2012-01-12 11:26
吃吃户
阅读(231)
推荐(0)
boost图库简单操作
摘要:1 #include <boost/graph/graph_traits.hpp> 2 #include <boost/graph/adjacency_list.hpp> 3 #include <boost/graph/dijkstra_shortest_paths.hpp> 4 using namespace boost; 5 6 #include <iostream> // for std::cout 7 #include <utility> // for std::pair 8 #include <algorithm>
阅读全文
posted @
2011-11-10 10:22
吃吃户
阅读(664)
推荐(0)