By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,389 Members | 1,795 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,389 IT Pros & Developers. It's quick & easy.

Using Vectors vs. Arrays

P: n/a
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?

Sep 25 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"ucfcpegirl06" <tr**************@gmail.comwrote:
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-lit...html#faq-13.10

--
There are two things that simply cannot be doubted, logic and perception.
Doubt those, and you no longer*have anyone to discuss your doubts with,
nor any ability to discuss them.
Sep 25 '06 #2

P: n/a
In article <11*********************@e3g2000cwe.googlegroups.c om>,
tr**************@gmail.com says...
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<linelines;

std::ifstream infile("file");

std::istream_iterator<linedata(infile), end;

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

--
Later,
Jerry.

The universe is a figment of its own imagination.
Sep 27 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.