Using Vectors vs. Arrays

U

ucfcpegirl06

Hello,

I have a file that I am reading date from.

File format is as follows:

a 556644f3
b 44545351
......

I want to read the entire contents of this file into a 2-D array or
vector.

I'd like to use vectors because it easily allows me to do what I need
to with this data.

My question is there are a lot of these data entries in this file and I
don't know how many.

I want to dynamically create this array or vector with this data with
the row being 1 data entrie and the columns being the number of entries
there are.

How do I do this using vectors?
 
D

Daniel T.

ucfcpegirl06 said:
Hello,

I have a file that I am reading date from.

File format is as follows:

a 556644f3
b 44545351
.....

I want to read the entire contents of this file into a 2-D array or
vector.

I'd like to use vectors because it easily allows me to do what I need
to with this data.

My question is there are a lot of these data entries in this file and I
don't know how many.

I want to dynamically create this array or vector with this data with
the row being 1 data entrie and the columns being the number of entries
there are.

How do I do this using vectors?

Wrap a vector into a 2D array class. There is a start of one on the FAQ:
http://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-13.10
 
J

Jerry Coffin

Hello,

I have a file that I am reading date from.

File format is as follows:

a 556644f3
b 44545351
.....

I want to read the entire contents of this file into a 2-D array or
vector.

class line {
char a;
int b;
};

std::vector<line> lines;

std::ifstream infile("file");

std::istream_iterator<line> data(infile), end;

std::copy(data, end, std::back_inserter(lines));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top