Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ifstream ifs ( path );
- string * in_file;
- int count = 0;
- while ( !ifs.eof() )
- {
- ++count;
- if ( count == 1 )
- {
- in_file = new string[1];
- }
- else
- {
- // Dynamically allocate another space in the stack
- string *old_in_file = in_file;
- in_file = new string[count];
- // Copy over values
- for ( int i = 0 ; i < ( count - 1 ) ; i++ )
- {
- in_file[i] = old_in_file[i];
- }
- delete[] old_in_file;
- }
- // After doing some debugging I know this is the problem what am I
- // doing wrong with it?
- getline(ifs,in_file[count - 1]);
- }
- Hello
- Bye
- See you later
- in_file [0] = Hello
- in_file [1] = Bye
- in_file [2] = See you later
- std::string str;
- std::vector <std::string> vec;
- while ( std::getline(ifs,str) )
- {
- vec.push_back(str) ;
- }
- for(size_t i=0;i<vec.size();i++)
- in_file[i] = vec[i];
- while ( !ifs.eof() )
- while ( ifs.good() )
- std::string line;
- while ( std::getline(ifs, line) ) {
- if (line.empty()) // be careful: an empty line might be read
- continue;
- ...
- }
- std::string word;
- while ( ifs >> word ) {
- ...
- }
- std::ifstream ifs(path);
- std::vector<std::string> lines;
- std::string line;
- while ( std::getline(ifs, line) )
- {
- // skip empty lines:
- if (line.empty())
- continue;
- lines.push_back(line);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement