i am trying to save file data to int array their are three files and every file contain more than 1 million records and i don't know how to save this data to array..............
file look like
12000
135680
69857
5986
.
.
.
.
.
anyone please help me everytime i run the code the error show overflow.........................

Recommended Answers

All 2 Replies

You need to either store the data externally, or have plenty of memory. Don't use an array per-se, or you will get a stack overflow as you are seeing. Use a C++ vector<int> to store the data. It will resize itself intelligently as you add data to it. It will be on the heap so a stack overflow won't happen.

Also, if you want the data to be sorted, then use a set<int> or multiset<int>. A set is ordered, where a vector is not, and it will only allow unique values (duplicates are rejected). A multiset will allow multiple identical values, so it may be appropriate if you want to see how many instances of 1234 you have, for example.

Here is the reference doc for set/multiset: http://www.cplusplus.com/reference/set/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.