Im doing some simple fileinput.. I am having issues resetting the file read to the start of the file. Basically If I run the function twice it won't work, once is fine though! :/ . I tried .seekg() but that didn't seem to work either. I am probably doing something arseways.. Anybody got any clues.
Code:#include <iostream> #include <string> // The next line is required for input and output file IO #include <fstream> using namespace std; void main() { string line,songCount,songChoice,title; bool printOut = false; int exitLoop = 0; int menuChoice = 0; ifstream fileInput; fileInput.open("hnr0.abc", ios::in); cout << "Trad Music Selector:" << endl << endl; do { cout << "Menu Options: \n 1. Print List of songs \n \n enter choice: " ; cin >> menuChoice ; switch(menuChoice){ fileInput.close(); fileInput.open("hnr0.abc", ios::in); case 1: while(!fileInput.eof()) { getline(fileInput,line);//read a line from data.txt and put it in a string /*if the first two characters X: print a blankline to seperate titles. After X: is found print all titles on the same line seperated by :*/ if(line.find("X:")==0) { cout << endl << endl; } else if(line.find("T:")==0) { title = line.substr(2,string::npos); cout << title <<":" ; } } cout << endl << endl; break; } }while(exitLoop!=1); }



LinkBack URL
About LinkBacks


