cuốn sách gpt4 ai đã làm

c++ - vectơ cặp số nguyên với vectơ vectơ số nguyên

In lại Tác giả: Walker 123 更新时间:2023-11-28 01:16:15 27 4
mua khóa gpt4 Nike

我怎么去

std::vector<>>

只是

std::vector<>>

?有真正有效的方法吗?

câu trả lời hay nhất

我会做这样的事情:

#include 
#include

int chính()
{
//Vector of pairs
std::vector<>> pairs = { {1,1},{2,2} };
//New vector
std::vector<>> vec;
//Allocate memory for new vector
vec.reserve(pairs.size());

for (auto &p : pairs)
{
//Create vector with first and second element of pair
std::vector v = { p.first, p.second };
vec.push_back(v);
}

trả về 0;
}

更新:为避免复制,您可以将 vector 移动到新 vector vec.push_back(std::move(v));.

关于c++ - 整数对 vector 到整数 vector vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58636873/

27 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress