Solved

fstream !!! how to read

Posted on 2000-05-11
5
301 Views
Last Modified: 2010-04-02
I wrote simple program which use fstream to write 480000 integers in file
That part work fine. But I dont know how to read data from that file in int array;
I tryed to use ifstream but I'm not getting my values back;
I'm new to c++ and this subject so if possible give me the code which can open file and read all values inside it


Regards
Vedran
0
Comment
Question by:xtvca
  • 3
  • 2
5 Comments
 
LVL 5

Expert Comment

by:Wyn
ID: 2801557
null
0
 
LVL 5

Accepted Solution

by:
Wyn earned 20 total points
ID: 2801561
Hi xtvca:

You can write it this way:

int main(int argc, char* argv[])
{
      ofstream of("my.dat");
      for(int i=0;i<=48000;i++)
            of<<???<<endl;
      return 0;
}

And read back:
int main(int argc, char* argv[])
{        int dada[48000];
      ifstream if("my.dat");
      for(int i=0;i<48000;i++)
            if>>dada[i];
      return 0;
}

Regards
Eirnava...
0
 

Author Comment

by:xtvca
ID: 2804896
I'll try
Thanks
0
 

Author Comment

by:xtvca
ID: 2836333
sorry for delay

this shold work but it has some problem (in my case)

No mather i found some other way to deal with it

regards
0
 

Author Comment

by:xtvca
ID: 2847545
Comment accepted as answer
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question