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

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -