stdvector

    0熱度

    2回答

    以下是有疑問的片段: typedef std::vector<unsigned char> QInput; // defined in an external library std::vector<QInput> extvec; // defined in a separate function 問題1:是extvec嵌套向量? 問題2:如何打印出extvec的內容? 我已經嘗試使用St

    0熱度

    2回答

    我想知道以下哪種方法拋出用戶定義的異常時出錯將是更好的方法。對我而言,就像不那麼有經驗的人一樣。但我很好奇,想知道這兩者之間是否會有所不同,如果是的話,是什麼。 std::vector<int> container {1, 2, 3, 4, 5}; int function1(int x, int y) { if(x < 0 || y < 0) throw USER_D

    2熱度

    4回答

    這與How to convert a vector<char*> to a vector<string>/string問題相反。 我有一些傳統的例程與vector<char*>一起使用,所以我需要改變我的vector<string>。 這是我拿出: std::vector<char*> charVec(strVec.size(),nullptr); for (int i=0; i<strVec.

    -2熱度

    3回答

    有 int x{5}; std::vector<int> vect; vect.push_back(x); 和 int x{5}; std::vector<int> vect; vect.at(0) = x;

    4熱度

    2回答

    對於某些類型的T,請考慮std::vector<T>。我收到一個指向這種類型的指針到一個函數中,還有一個T的實例; t說。 我的功能看起來是這樣的: void bar(std::vector<T>* foo, const T& t) { foo->clear(); foo->push_back(t); } 有沒有辦法我寫的函數體中的一個聲明?由於不存在適當的賦值運算符,

    3熱度

    2回答

    我在a.h一個以下設計: class A { virtual void updateCoefficients(std::string /*state*/, std::vector<std::vector<double>>& /*coefs*/, double /*reward*/) {} protected: std::map<std::string

    1熱度

    1回答

    我想看看向量v1是否在向量v2內。例如,如果v1 =(b,a)和v2 =(g,e,f,a,b)。我需要在v2中檢查b和一個禮物。 我下面的代碼只有在訂單相同時纔會幫助我。 std::search(v2.begin(), v2.end(), v1.begin(), v1.end()); 即,如果V2 =(G,E,F,B,A) 目前我通過以下方式 for (std::vector<std::str

    4熱度

    2回答

    我想持有一個基類實例的向量,無需對象切片(這樣我也可以存儲Base的子實例而沒有問題),同時保持多態行爲而不通過複製值添加到列表中,而是通過引用。 考慮以下源文件: #include <iostream> #include <string> #include <vector> #include <memory> class Entity { public: Entity()

    0熱度

    3回答

    我看到這個的方式,它們都具有相同的功能,除了std :: vector看起來更加靈活,所以何時需要使用數組,並且可以使用std ::只有矢量? 這不是一個新問題,原來的問題沒有我一直在尋找

    1熱度

    1回答

    以下(還原的)代碼非常糟糕由串聯GCC的 #include <vector> #include <cilk/cilk.h> void walk(std::vector<int> v, int bnd, unsigned size) { if (v.size() < size) for (int i=0; i<bnd; i++) { std::vector<in