stl-algorithm

    2熱度

    2回答

    在C++中使用STL,我將如何應用函數來獲取std::string(值的打印表示)並將std::string(s)應用到按浮點鍵排序的集合中的每個值它來自應用於地圖中每個對應值的另一個函數? 換言之,我想迭代映射中的鍵值對,並創建一組新的鍵值對,其中新鍵和值是舊值的函數。 double getNewKey(origValue value); std::string getNewValue(ori

    12熱度

    1回答

    可能重複: Why does the C++ standard algorithm 「count」 return a ptrdiff_t instead of size_t? 有算法std::count/std::count_if在標準C++。 template<class InputIterator, class T> typename iterator_traits<InputIterato

    3熱度

    3回答

    假設我們想從一個向量int s中刪除重複的值。通常的解決方案是對矢量進行排序並使用擦除刪除方式擦除重複項。但是我們需要維護不會被刪除的元素的順序,所以我們無法排序。所以有人會想出這樣的斷言,並使用與remove_if算法: struct comp { std::set<int> s; comp() : s() {} bool operator()(int i)

    0熱度

    1回答

    我試圖使用remove_copy_if將iterable直接複製到stdout到ostream_iterator。 remove_copy_if保證return value到iterator到輸出範圍的末尾。通過找出輸出迭代器的開始與返回迭代器之間的距離,此返回值有助於確定複製到目標的元素的數量。這在使用容器時很有意義,但如何使用相同的功能來確定複製到目標的元素的數目(如果其爲ostream_it

    0熱度

    1回答

    我有一個自定義類和std::vector填充此類的對象。我想在此陣列中執行binary_search。 我重載運算上我的課是這樣的: bool operator ==(const someClass&); bool operator > (const someClass&); bool operator < (const someClass&); 和他們工作的罰款(他們有機構,是的)。 現

    9熱度

    2回答

    我正在C++應用程序上工作。 我有 vector<Point2f> vectorAll; vector<Point2f> vectorSpecial; Point2f定義typedef Point_<float> Point2f; vectorAll有1000點,同時具有vectorSpecial 10分點的2個向量。 第一步: 我需要根據他們的vectorAll爲了在vectorSpeci

    5熱度

    3回答

    class Widget; std::vector< std::shared_ptr<Widget> > container class Criterium { public: bool operator()(const Widget& left, const Widget& right)const; }; 我怎樣才能根據繞圈,排序的容器,但未定義像另一個繞圈: cla

    0熱度

    1回答

    這個問題已經在SO中完成了死亡。這裏是我的版本,使用傳統算法的STL函數來反轉字符串,然後翻轉單詞。有沒有使用循環更優雅的soln? std::string something; std::getline(std::cin, something); std::reverse(something.begin(), something.end()); for (size_t i = 0, siz

    1熱度

    1回答

    我有以下手寫循環來處理括號表達式: while (!punctuators.empty() && punctuators.back().kind != '(') { output.push_back(punctuators.back()); punctuators.pop_back(); } if (punctuators.empty()) throw inva

    4熱度

    1回答

    以下代碼在排序向量時崩潰。 #include<cstdio> #include<vector> #include<algorithm> using namespace std; struct Foo { int x; // int y; Foo() : x(0) {} }; struct Cmp { bool operator() (Fo