ICode9

精准搜索请尝试: 精确搜索
  • c-为什么不能从元组分配对,但是可以从对分配元组?2019-10-10 18:06:41

    我不清楚为什么分配元组< X,Y> = pair< X,Y> 但是分配对X,Y =元组X,Y是不合法的. std::pair<int, double> x { 1 , 5.5}; std::tuple<int, double> y { 1 , 5.5}; int a; double b; std::tie(a,b) = x; std::tie(a,b) = y; x = y; // THIS LIN

  • c-将std :: map复制到对的std :: vector中2019-10-10 12:08:37

    我正在尝试将地图复制到向量对中,因此可以根据向量对中的第二个数据成员对向量进行排序.我已经这样解决了: void mappedWordsListSorter(){ for (auto itr = mappedWordsList.begin(); itr != mappedWordsList.end(); ++itr){ vectorWordsList.push_back(*itr); } sort(v

  • 如何在C中使用自定义比较器创建std :: set?2019-10-09 14:16:58

    如何创建一组对,其中的对(对)的元素使用自定义布尔函数排序?我写 set <pair<int,int>,compare> myset; 并得到错误:参数2的类型/值不匹配,预期为类型,得到“比较” 我将“比较”定义为 bool compare(pair <int,int> g1, pair <int,int> g2) { return (g1.second-g1.first > g2

  • make_pair和大括号{}之间的区别,用于在C中分配一个对?2019-10-09 10:17:44

    我没有找到回答这个问题的人,以下内容之间是否有区别: v.push_back({x, y}); 和: v.push_back(make_pair(x, y)); 假设v是这样声明的: vector<pair<int,int> > v; 解决方法:我在一个在线编译器中进行了尝试,据我所知,make_pair的优化程序集与{}语法相同. https://godbolt.org/z/

  • c – 我可以使用std :: pair,但重命名.first和.second成员名称?2019-10-06 08:18:00

    我遇到的一个常见设计问题是,我将两个变量捆绑在一起,然后失去了以有意义的方式引用它们的能力. std::pair<int,int> cords; cord.first = 0; //is .first the x or y coordinate? cord.second = 0; //is .second the x or y coordinate? 我考虑过编写基本结构,但后来我失去了很

  • C从对列表中删除2019-10-03 08:07:54

    很简单:我有以下代码,擦除方法不起作用.我没有看到任何问题,因为如果我去http://www.cplusplus.com/reference/list/list/erase/,语法是:iterator erase(iterator position); list<pair<string,int>> l0 { { "name1", 20 }, { "name2", 30 }, { "name3", 40 } }; for(

  • 通过第一个元素然后通过C中该对的第二个元素对对矢量进行排序?2019-09-29 16:06:18

    参见英文答案 > Sorting a std::vector<std::pair<std::string,bool>> by the string?                                    4个 如果我有一个向量< pair< int,int> &GT数据类型,通过该对的第一个元素对它进行排序的可接受方式是什么,然后如果

  • 如何在C中创建一组无序的整数?2019-09-28 13:05:51

    以下程序不会编译一组无序的整数对,但它会对整数进行编译. unordered_set及其成员函数可以用于用户定义的类型,我该如何定义它? #include <unordered_set> ... class A{ ... private: std::unordered_set< std::pair<int, int> > u_edge_; }; 编译错误: error: no matching

  • c – 配对相等的运算符重载以插入集合2019-09-02 10:07:53

    我想添加一对< int,int>一套.如果一对在集合中与另一个值共享相同的两个值,则不应插入它. 这是我的非工作代码: typedef std::pair<int, int> PairInt; template<> bool std::operator==(const PairInt& l, const PairInt& r) { return (l.first == r.first && l.second ==

  • c – 无法访问对向量中的值2019-09-02 08:06:46

    我有一个对矢量作为对象内的字段.所述对象具有一种方法,其中我需要访问向量中的对中的值.我使用迭代器指向我想要访问的向量中的位置.以下是包含向量的代码片段: 在头文件中: vector<pair<double, double> > points; vector<pair<double, double> >::iterator headingTo; 在构造函

  • c – 如何重载自定义std :: sort比较函数?2019-08-31 10:07:01

    使用std :: sort时,如何重载我正在使用的自定义比较函数? #include <string> #include <vector> #include <iostream> #include <algorithm> class Misc { public: // Comment out the next three lines to compile without problems. static bool sortPair(const s

  • 有没有一种很好的方法将2D C数组转换为成对?2019-08-30 15:05:18

    我有一个2d数组,效果为{{1,2},{3,4},{5,6} …}或类似.我想将每一行转换为一对,以便将它们作为顶点插入到Boost邻接列表图中.最好的方法是什么(即将每一行转换成一对)?解决方法:迭代外部数组并使用以下内容构造std :: pair对象: 的std ::对&LT INT,INT&GT(ARR [I] [0],ARR [I] [1]);

  • c – 使用`std :: pair`值进入`std :: unordered_map`2019-08-29 09:15:30

    参见英文答案 > std::map emplace without copying value                                    2个 我正试图将值放入std :: unordered地图,如下所示: std::unordered_map<std::string, std::pair<std::string, std::string>> testmap; testma

  • c – 初始化std :: array时,通过std :: initializer_list初始化std :: pair不起作用?2019-08-28 11:06:42

    参见英文答案 > How should I brace-initialize an std::array of std::pairs?                                    2个 我想通过std :: initializer_list初始化std :: pair的std :: array. pair<int, int> p = {3,4};//ok array<pair<char,

  • c – 这个记忆会被正确释放吗?2019-08-27 09:07:33

    我有一对指针让我们假设std :: pair< A *,B *> *指针对.我分配了内存,使用后我调用了delete pointerpair. 它还会调用删除A并删除B并完全释放内存吗? 如果我只调用删除A并删除B但没有删除指针对,那么它是内存泄漏吗?解决方法:没有………….

  • c – 对大对数组进行排序2019-08-25 05:05:53

    我需要一种算法,根据每对的第一个元素对一对数组进行排序.以下代码适用于v_size< ~2 ^ 19,但是,在接近2 ^ 19的大小时,由于分段错误而崩溃.是什么原因?大小约为524000并不大. (我正在使用gcc(Debian 4.7.2-5)4.7.2) #include <iostream> #include <algorithm> #include <iterator>

  • c – 访问std :: pair数组的元素时出错2019-07-30 00:06:35

    我已经定义了一对数组,如下所示: std::pair<int,int> delta[4]; delta[0] = std::make_pair(0,1); delta[1] = std::make_pair(1,1); delta[2] = std::make_pair(1,0); delta[3] = std::make_pair(1,-1); 但是当我尝试访问以下元素时: delta[2].first 我收到如下错误: binary '['

  • 在c中排序一对矢量2019-07-28 10:08:53

    #include "bits/stdc++.h" using namespace std; int main() { int i,j; vector< pair<int,int> > v; v.push_back(make_pair(4,2)); v.push_back(make_pair(1,3)); v.push_back(make_pair(5,4)); sort(v.begin(), v.end()); for(i=0;i&

  • memset c中的一对数组2019-07-27 07:06:28

    我有一对对.我想在这个数组上使用memset来生成0,1或-1.我该怎么做?这是我们一直做的正常程序吗? 该对和数组是: std::pair<int, int> ar[100][100]; 解决方法:不要在任何不是POD类型的东西上使用memset(std :: pair不是) – 它不会很好(这是不明确的行为). 具有构造函数的类需要调用

  • c – 使用std :: move on pair.first会使pair.second无效吗?2019-07-24 20:08:05

    我目前在项目中有以下代码: std::vector<int> vectorOfFirsts; std::set<double> setOfSeconds; std::list<std::pair<int,double>> cachedList; // do something to fill the list for (const auto& pair : cachedList) { vectorOfFirsts.push_back(pai

  • c – 为什么我不能使用make_pair来绑?2019-07-24 17:14:54

    我试图模仿tie前C 11的行为. pair<int, int> test() { return make_pair(13, 42); } int main() { int a = 1, b = 2; pair<int&, int&>(a, b) = test(); cout << a << ' ' << b << endl; } This works然而,

  • c – 如何指定对的比较?2019-07-23 19:14:36

    有一对 pair <string, int> myPair; 我有一个myPair对象的向量.我需要在对的第二个值即整数上使用make_heap将其转换为最小堆.我怎样才能做到这一点?我不确定如何定义比较操作. I know I need something like this for heap to operate. But not sure where to put it: bool ope

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有