c++ - How to read same file twice in a row -


i read through file once find number of lines contains read through again can store data of each line in array. there better way read through file twice closing , opening again? here got afraid it's inefficient.

int numofmappings = 0; ifstream settingsfile("settings.txt"); string setting; while(getline(settingsfile, setting)) {     numofmappings++; } char* mapping = new char[numofmappings]; settingsfile.close(); cout << "numofmappings: " << numofmappings << endl; settingsfile.open("settings.txt"); while(getline(settingsfile, setting)) {     cout << "line: " << setting << endl; } 

settingsfile.clear(); settingsfile.seekg(0, settingsfile.beg); 

Comments