Seekg()

Hello everyone, I have a problem when working with file.
I use seekg() function to go to the beginning of the file, but my code doesn't work. I don't know why. Here is what I try:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    ifstream f;
    int x, y, z = 0;
    
    f.open("test.txt");
    f >> x >> y;
    cout << x << " " << y << endl;
    f.seekg(0,ios::beg);
    f >> z;
    cout << z << endl;
    f.close();
    system("PAUSE");
    return 0;
}


In file "test.txt", I write "10 20". So, if it work well, the value of z must be 10, but it's 0. I don't know why.
Could you help me?
Thank you very much for your help!
Topic archived. No new replies allowed.