so i'm making class member function "insert" copy string array classes contents vector array.
this abort error keeps popping saying i'm going past vector end, don't understand why....
here's code:
///////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////// map class ///////////////////// class map { private: /////////////////////////////////////////// map variables /////////////// string _name; vector <string> _contents; public: map(string name){_name = name; _contents.reserve(56);}; ~map(){}; string getname() { return _name; }; vector <string> getcontents() { return _contents; }; /////////////////////////////////////////// insert //////////////////////// // string* array of 56 strings; bool insert(string* _lines_) { (int = 0; < 3; i++) { _contents[i] = _lines_[i]; } return true; }; };
if need more info ask! thanks!
actually, don't need copy them yourself. can use std::vector::assign
convert c-style array
std::vector
.
vector::assign
assigns new content vector object, dropping elements contained in vector before call , replacing them specified parameters.
example
string sarray[3] = {"aaa", "bbb", "ccc"}; vector<string> svector; svector.assign(sarray, sarray+3); ^ ok, svector contains 3 elements, "aaa", "bbb", "ccc"
more details
Comments
Post a Comment