c++ - return and call dynamic string array -
i created class:
data::data(char szfilename[max_path]) { string sin; int = 1; ifstream infile; infile.open(szfilename); infile.seekg(0,ios::beg); std::vector<std::string> filerows; while ( getline(infile,sin ) ) { filerows.push_back(sin); } } after created this:
std::vector<std::string> data::filecontent(){ return filerows; } after call filecontent() somewhere, this:
data name(szfilename); messagebox(hwnd, name.filecontent().at(0).c_str() , "about", mb_ok); but doesnt work... how call this?
std::vector<std::string> filerows; while ( getline(infile,sin ) ) { filerows.push_back(sin); } does not work because declare filerows in constructor, once constructor ends filerows destroyed.
what need move filerows declaration outside of constructor , make class member:
class data { ... std::vector<std::string> filerows; }; then shared functions in class.
Comments
Post a Comment