ifstream returns wrong output

Hello,

I was ttying to write a letter into a file and to extract the letter aftwerwards.

The writing does work.
The reading returns "-1".

What is wrong?

thanks

int main

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


int _tmain(int argc, _TCHAR* argv[])
{	int ch;

	ofstream ouput("bla.txt");
	ifstream input("bla.txt");

	ouput.put('g');
	ch =input.get();
	cout << ch;
	cin.get();
	return 0;
}
the problem could be that you open the input stream before writing on it.
try to create just a fstream both for output and input
Last edited on
Thank you. It works now.
Topic archived. No new replies allowed.