Solved

Reading ile and parsing

Posted on 2003-11-29
1
174 Views
Last Modified: 2010-04-02
I am trying to read the file below and store to array.
Each number is between 1 – 80 and number of line will be between 1 – 10,000.
Also, is it good idea to use array since this file might contains 10,000 of line?

Ex)
3:  1,  4,  5, 10, 14, 15, 16, 19, 22, 25, 26, 37, 38, 42, 50, 56, 62, 70, 74, 80
1:  6, 12, 27, 28, 29, 30, 33, 36, 37, 39, 41, 43, 46, 49, 56, 57, 59, 62, 73, 80
….

….
….
0
Comment
Question by:dkim18
1 Comment
 
LVL 9

Accepted Solution

by:
tinchos earned 100 total points
ID: 9843419
Hi dkim18,

If I were you I would not use an array but a map whose key is the line number and whose value is a list of numbers

typedef list< int > NumberList;
typedef map< int, NumberList > NumberMap;

There, you will be able to add like this

NumberList myList;

myList.push_back( 1 );
myList.push_back( 4 );
myList.push_back( 5 );
myList.push_back( 10 );
myList.push_back( 14 );

// And so on
NumberMap myMap;
myMap[ 3 ] = myList;

and that will store the first line of code

Hope this helps

Tincho
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

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…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

708 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

19 Experts available now in Live!

Get 1:1 Help Now