Solved

fstream !!! how to read

Posted on 2000-05-11
5
297 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
Comment Utility
null
0
 
LVL 5

Accepted Solution

by:
Wyn earned 20 total points
Comment Utility
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
Comment Utility
I'll try
Thanks
0
 

Author Comment

by:xtvca
Comment Utility
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
Comment Utility
Comment accepted as answer
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now