push-back

Displaying a vector of strings in C++

夙愿已清 提交于 2020-12-12 10:29:26
问题 I'm sorry if this is a repeat question but I already tried to search for an answer and came up empty handed. So basically I just want to add strings (single words) to the back of a vector and then display the stored strings as a single string. I am quite the rookie. #include <iostream> #include <vector> #include <string> #include <cctype> using namespace std; int main(int a, char* b []) { vector<string> userString; string word; string sentence = ""; for (decltype(userString.size()) i = 0; i <

Weird behaviour with class fields when adding to a std::vector

浪尽此生 提交于 2020-05-09 20:06:41
问题 I have found some very weird behaviour (on clang and GCC) in the following situation. I have a vector, nodes , with one element, an instance of class Node . I then call a function on nodes[0] that adds a new Node to the vector. When the new Node is added, the calling object's fields are reset! However, they seem to return to normal again once the function has finished. I believe this is a minimal reproducible example: #include <iostream> #include <vector> using namespace std; struct Node;

push_back with derived class

我只是一个虾纸丫 提交于 2020-02-04 04:06:26
问题 I want to create an array of objects and I want to use a certain constructor. std::vector<Modul> arrDigOut; arrDigOut.push_back(Modul(IDC_CHECK1, this, "GVL.DigOut1", pAddr)); This works as long as DigOut is not a derived class. When I derive it and use the class DigOut it fails: class Modul { protected: int id; int nErr; void* plcVar; bool bDigOut; PAmsAddr pAddr; ULONG lHdlVar; CButton* pBt; public: Modul(); //Modul(int ID, Cbeckhoff_frontendDlg* pCbeckhoff,void* pVar,PAmsAddr pAdr) //{ //

push_back with derived class

时光怂恿深爱的人放手 提交于 2020-02-04 04:05:52
问题 I want to create an array of objects and I want to use a certain constructor. std::vector<Modul> arrDigOut; arrDigOut.push_back(Modul(IDC_CHECK1, this, "GVL.DigOut1", pAddr)); This works as long as DigOut is not a derived class. When I derive it and use the class DigOut it fails: class Modul { protected: int id; int nErr; void* plcVar; bool bDigOut; PAmsAddr pAddr; ULONG lHdlVar; CButton* pBt; public: Modul(); //Modul(int ID, Cbeckhoff_frontendDlg* pCbeckhoff,void* pVar,PAmsAddr pAdr) //{ //

push_back with derived class

荒凉一梦 提交于 2020-02-04 04:05:08
问题 I want to create an array of objects and I want to use a certain constructor. std::vector<Modul> arrDigOut; arrDigOut.push_back(Modul(IDC_CHECK1, this, "GVL.DigOut1", pAddr)); This works as long as DigOut is not a derived class. When I derive it and use the class DigOut it fails: class Modul { protected: int id; int nErr; void* plcVar; bool bDigOut; PAmsAddr pAddr; ULONG lHdlVar; CButton* pBt; public: Modul(); //Modul(int ID, Cbeckhoff_frontendDlg* pCbeckhoff,void* pVar,PAmsAddr pAdr) //{ //