Displaying Sequential Record

cherries's Avatar, Join Date: Dec 2007
Newbie 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);
	}
0
cherries's Avatar, Join Date: Dec 2007
Newbie Member
sooolveeed! thanks~~