stl

    -2热度

    3回答

    之前我有很多矢量(按10^4的顺序,甚至更多!)我将从流中获取更多矢量。因此,举例来说,我有 v1 = 1 0 4 1 1 v2 = 1 1 2 5 3 6 2 v3 = 0 1 1 5 0 我有10^4这样的载体 现在,我在输入得到一个向量v4 = 0 1 1 5 0,我想检查它是否曾经出现过,你如何建议我这样做? 我会列出我想到的技术,并陪伴他们的错误: 为同一使用std::map,或std:

    2热度

    1回答

    假设我有一个容器的迭代器std::list::iterator it = mylist.begin(),我叫 iterator it2 = std::next(it,1); 是否std::next检查,如果it == mylist.end()?

    1热度

    1回答

    #include <bits/stdc++.h> using namespace std; vector<int> func() { vector<int> a(3,100); return a; } int main() { vector<int> b(2,300); //b.swap(func()); /* why is this no

    -2热度

    1回答

    eq是每个元素的形式为e =(F =(int,double),S =(int,double))的事件队列。 当我在事件队列I中处理事件e =(F,S)时,从set< pair<int, double> > el插入或删除或插入e.S。在删除e.S时,可以假设e.S已经在el中。 但是,当我试图通过el.erase(e.S)从el删除e.S它给出了一个错误: segmentation fault 1

    0热度

    1回答

    我有线性代数的类,特别是矢量和矩阵。这些包含其他std :: vectors(或std :: maps)作为它们的'数据'字段。 在基于for循环的范围内对这些进行迭代很容易。但我想将这些字段设置为私有的,并且对我的自定义类进行更自然的迭代,这样我就可以在类本身上执行基于范围的循环。 我试着看std :: vector <> .begin()等的函数定义。然后我试图以这样一种方式实现它,即所有的迭

    1热度

    1回答

    我有一个微不足道的分配器: // alloc.h #include <cstdlib> #include <new> #include <iostream> template <class T> struct Mallocator { typedef T value_type; Mallocator() { std::cout << "default c

    -9热度

    1回答

    我想知道迭代器的大小(指针的泛化)。需要更多信息what is the type of an iterator in STL?

    1热度

    1回答

    我从std :: string中间连接3个字符。如果我通过char来实现char,我会得到预期的结果,但是如果我只用一个表达式来完成,我会得到一个奇怪的结果。为什么? #include <string> #include <iostream> using namespace std; int main() { string s1 = "abcdefghijklmnopq";

    3热度

    2回答

    有时会出现这样的情况:我们有一个工厂生成std :: unique_ptr向量,稍后我们想要在类/线程之间共享这些指针/你的名字。所以最好使用std :: shared_ptr代替。当然还有一种方式转换的std :: uniqe_ptr到std :: shared_ptr的 std::shared_ptr<int> sharedV; std::unique_ptr<int> uniqueV(ne

    4热度

    1回答

    因此,在我了解std::error_code如何运作的旅程中,我开始怀疑我们是否真的需要std::error_condition和std::error_category。我试图实现this和this教程中的内容,并且工作量并非易碎,而且相当脆弱(我目前一直在试图弄清楚为什么此代码会导致链接错误与重复符号有关。 是不是更容易继承std::error_code,加message财产&方法,然后让std