Advertisement

problem with reading in a file

Started by July 20, 2000 02:21 PM
4 comments, last by omegasyphon 24 years, 5 months ago
ok i have a file defined as so 00 00 00 01 02 01 01 01 01 now i open the file the following way ifstream fin("data.dat"); ofstream fout("data1.txt");
        
while (!fin.eof())
{
     fin<<a;
     fout>>a;
}
fin.close();
fout.close();
        
now when i go to open my output file data.txt all i get is 1 zero in the top left corner and i dont know why? also im using msvc5++ on win98 Edited by - omegasyphon on 7/20/00 2:48:58 PM
What are you trying to do? Do you want to fill data1.txt with what's in data.dat? If so, then you shouldn't be using cin or cout. You should be doing:

    fin << a;fout >> a;    


-> Briar LoDeran <-

Edited by - BriarLoDeran on July 20, 2000 3:30:44 PM
Advertisement
    ifstream fin("data.dat");ofstream fout("data1.txt");int a;fin >> dec;while (!fin.eof()){   fin >> a;   fout << a;}fin.close();fout.close();    




"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions

well i forgot to say that im trying to read in the data.dat file and load it into an array of 3x3 but right now im just doing testing to get my algorithm working to read it into an array and display it in my data.txt file to see if it works
[source]
ifstream fin("data.dat");
int array[3][3];
fin >> dec;
for (int i = 0; i < 3; i++)
{
for (int k = 0; k < 3; k++)
{
fin >> dec[k];
}
}
fin.close();


"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions

how does the array[3][3] fit into your code and also what does fin>>dec do when u add it before the loop?

This topic is closed to new replies.

Advertisement