1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Displaying Sequential Record

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

  1. cherries

    cherries New Member

    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

    sooolveeed! thanks~~
     

Share This Page