push-back

    2熱度

    2回答

    我有以下代碼: #include <iostream> using std::cin; using std::cout; using std::endl; #include <vector> using std::vector; class Quote { public: Quote() = default; Quote(const std::string &boo

    0熱度

    2回答

    我試圖加快矢量::的push_back時容量不能被預測 當儲備可用的push_back在容器的端部將新的元素,然後結束標記被移動的載體。在使用所有保留後,push_back可能會觸發重新分配,這是一個緩慢的過程。 爲了加快速度,預留幾個即將到來的push_back重新生成,沒有重新分配時,爲空。你認爲這個代碼如何幫助實現這個目標? #ifndef __VECTOR_HPP #define __V

    0熱度

    1回答

    爲什麼push_back無法正常工作?很困惑,爲什麼它不與下面 using namespace std; void addItem(vector<string>& STRING, string item) { STRING.push_back(item); } int main() { string item; vector<string> STRING(

    -1熱度

    1回答

    請告訴我爲什麼這段代碼有運行時錯誤的原因。 我認爲addEmployee()函數是問題。 #include <iostream> #include <vector> #include <string> using namespace std; enum EmployeeLevel {fresh, sophomore, junior, senior}; class Employee {

    -5熱度

    2回答

    由於某些原因,我需要經常生成字符串,使用{'0','1','2','3'}中的字符。我當前的代碼使用的push_back()函數,看起來像: string test = "" test.push_back('0') test.push_back('2') test.push_back('3') // test would be "023" 我想存儲在一個char類型或者int類型的字符串

    0熱度

    1回答

    因此,該函數的目標是向1和所提供的整數(含)之間的數組添加奇數。這似乎是一個簡單的任務,但是,我似乎無法讓它成功地將整數添加到實際的數組。 void populate(std::vector<int> ary, int a) { for (int i = 1; i <= a; i++) { if (i % 2 != 0) { ary.p

    -2熱度

    2回答

    我在模板對象上使用push_back時非常困難。任何人都可以解釋爲什麼這個作品 list<int> mylist; int myInt; mylist.push_back(myInt); 但這不會。 list<KeyValuePair<T>> mylist; int myInt; mylist.push_back(myInt);

    -11熱度

    1回答

    push_back對於帶有函數更新值的向量,不允許爲什麼? std::vector<std::string>goin; goin.push_back(function(somestringvalue)); // why cant it take update value? void function(std::string& var) { var += "pre"; }

    0熱度

    3回答

    我有一個帶有座標和WayIds的大文件。我存儲在向量與下面的結構: struct SOne { double y, x, wayId; }; 文件看起來是這樣的: 52.8774,6.7442,777 52.8550,6.7449,777 52.8496,6.7449,776 在我的程序中,我已經過濾了我想繼續工作並存儲在名爲「way」的向量中的WayIds。用for循環我可以找

    0熱度

    5回答

    我正在使用矢量程序。所以我做的第一件事就是宣佈我的向量。 std::vector<double> x; x.reserve(10) (順便說一句,這是也被認爲是不好的做法?我應該只需要輸入std::vector<double> x(10)?) 然後我繼續分配值向量,並要求它的大小。 for (int i=0; i<10; i++) { x[i]=7.1; } std::cou