编曲!我就是这样做的,但它有点长。什么更紧凑? (我正在使用cpp 98!)
std::vector<Object> allObjs;
// ... allObjs gets filled ...
// Now get back a vector with only the first element in allObjs
std::vector<Object> justTheFirstElemOfObjs;
justTheFirstElemOfObjs.push_back(allObjs.front());
allObjs = justTheFirstElemOfObjs;
答案 0 :(得分:5)
allObjs.resize(1);
应该可以解决问题。