stlmap

    -4熱度

    1回答

    我試圖使用地圖作爲函數參數並獲取未定義的引用錯誤。 #include<iostream> #include<map> using namespace std; void word_frequency(map<string,int> &doc,ifstream &file){ } int main(){ map<string,int> doc1; ifstream fi

    -3熱度

    2回答

    宣言的作品,當我宣佈這樣一個迭代器: map<string,int>::iterator it, temp; 但是,當我宣佈它下面的方式會發生什麼? map<string,int>temp, ::iterator it; 是表示error: expected initializer before 'it' 這是爲什麼造成錯誤?

    13熱度

    3回答

    我寫了一個使用std :: map的小程序,如下所示。 int main() { map<int,float>m1; m1.insert(pair<int,float>(10,15.0)); //step-1 m1.insert(pair<float,int>(12.0,13)); //step-2 cout<<"map size="<<m1.size()

    0熱度

    3回答

    我有一個地圖定義爲: map < char, vector < unsigned char>> dict; 後的函數生成並添加內容到這個字典,我想下遍歷並打印各鍵:值對在循環。 for(auto it = dict.begin(); it != dict.end(); ++it) { cout << it.first << " : "; //how to output t

    0熱度

    2回答

    我有被存儲在std::multimap<int, S>一個S類: class S{ int _secondKey{0}; int _thirdKey{0}; }; 我想存儲相同關鍵的要素,基於排序的_secondKey類構件上,然後_thirdKey構件。 這可能在C++中完成嗎?我使用GCC 5.3

    0熱度

    2回答

    我正在使用C++ Builder XE7。我想用一個UnicodeString作爲鍵和一個類作爲值的映射。 這是我的課:Historique.h #ifndef HistoriqueH #define HistoriqueH #include <System.Classes.hpp> #include <string> class MyHistorique { public

    2熱度

    3回答

    我有這個經典問題。我有STL地圖< StudentName,Marks>其中StudentName是字符串,標記是整數。現在 ,在我的應用程序,多個線程正在訪問這個地圖: 查找StudentName。如果存在,增加其商標StudentName的 減少標記 添加StudentName到地圖 從地圖中刪除StudentName 問題:什麼是最有效的方法做上述的STL操作多線程環境中的地圖? 當前解決方

    2熱度

    3回答

    我有一個以下類型的結構,我計劃將它用作映射中的鍵。因此,我寫下如下的比較器。我想知道是否有更優雅而有效的方式來做到這一點。 可能會使用std :: pair或其他東西。 struct T { int a, b, c, d; bool operator< (const T& r) { if (a < r.a) return true else

    0熱度

    3回答

    比方說,我已經聲明 map< int , vector<int> > g1; vector< vector<int> > g2; 什麼是這兩者之間的相似點和不同點?

    2熱度

    1回答

    我創建一個object_ptr並將其插入stl映射中。然後在代碼的其他部分,我使用鍵找到對象,並從地圖中刪除值並刪除對象。似乎代碼有內存泄漏。我怎樣才能避免它? 這裏是代碼片段: void foo(){ Request * req = new Request(); MyMap.insert (std::pair<int, Request *> (address, req));