Solved

fstream !!! how to read

Posted on 2000-05-11
5
304 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

821 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