9 125 C:\Users\86198\Desktop\未命名1.cpp [Error] could not convert '{{0, 1}, {0, 2}, {0, 3}, {1, 4}, {1, 5}, {2, 5}, {2, 6}, {3, 7}, {6, 8}, {6, 9}, {7, 10}}' from '<brace-enclosed initializer list>' to 'std::vector<std::pair<int, int> >'
时间: 2023-06-18 14:07:22 浏览: 193
未命名1.cpp
这个错误提示是因为你在将一个大括号括起来的初始化列表直接赋值给了一个`vector<pair<int,int>>`类型的变量,但是它们类型不匹配,无法进行转换。
你可以将大括号括起来的初始化列表转换为一个`vector<pair<int,int>>`类型的变量的方法有两种:
1. 使用`vector`的构造函数进行初始化:
```
vector<pair<int,int>> vec = { {0, 1}, {0, 2}, {0, 3}, {1, 4}, {1, 5}, {2, 5}, {2, 6}, {3, 7}, {6, 8}, {6, 9}, {7, 10} };
```
2. 先定义一个空的`vector<pair<int,int>>`类型的变量,再使用`push_back()`函数将元素加入:
```
vector<pair<int,int>> vec;
vec.push_back({0, 1});
vec.push_back({0, 2});
vec.push_back({0, 3});
vec.push_back({1, 4});
vec.push_back({1, 5});
vec.push_back({2, 5});
vec.push_back({2, 6});
vec.push_back({3, 7});
vec.push_back({6, 8});
vec.push_back({6, 9});
vec.push_back({7, 10});
```
阅读全文