Displaying Sequential Record

Discussion in 'C++' started by cherries, Dec 20, 2007.

  1. cherries

    cherries New Member

    Joined:
    Dec 20, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    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);
    	}
    
     
  2. cherries

    cherries New Member

    Joined:
    Dec 20, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    sooolveeed! thanks~~
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice