Hello and thank you in advance. This is a very simple question but one that is getting on my nerves. What I want is just to ask for an integer to write to a file and then display every integer. I've learned how to either write to or display from a file and I've been successful at it but when I try to do both at a time it just asks me for the integer and don't display the numbers. I think it may be a problem related to fstream or to the position of the pointer.
Here is the program:
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <fstream>
using std::cout;
using std::cin;
using std::fstream;
using std::endl;
int a;
int x;
int main() {
fstream in;
in.open("op.txt", std::ios::app);
cout << "Write an integer" << endl;
cin >> x;
in << " " << x;
while (in >> a) {
cout << a << endl;
cout << in.tellg();
}
in.close();
return 0;
}