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