Solved

fstream !!! how to read

Posted on 2000-05-11
5
307 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

726 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