Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Displaying Sequential Record (http://www.go4expert.com/forums/displaying-sequential-record-t7940/)

cherries 20Dec2007 07:26

Displaying Sequential Record
 
Do you mean: (but it doesn't work, as it only goes back to the beginning of the same record)

Code:

        int n;
        int pos;
        int previous_pos;
        fstream f;
        f.open("info.txt");
        while (1)
        {
                previous_pos = f.tellg();
                getline (f, name);
                f >> gender;
                f >> age;
                f >> staffno;
                f >> telpno;
                f >> roomno;

                cout << "Name: " << name;
                cout << "\nGender: " << gender;
                cout << "\nAge: " << age;
                cout << "\nStaff No.: " << staffno;
                cout << "\nPhone No.: " << telpno;
                cout << "\nRoom No.: " << roomno << endl <<endl;
               
                cout << "<1> previous \t <2> next \t <0> exit\n";
                cin >> n;
               
                pos = f.tellg();

                if (n==1)
                        f.seekg(previous_pos);
                if (n==2)
                        f.seekg(pos);
        }


cherries 20Dec2007 15:26

Re: Displaying Sequential Record
 
sooolveeed! thanks~~


All times are GMT +5.5. The time now is 09:53.