Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Using Vectors vs. Arrays

Reply
Thread Tools

Using Vectors vs. Arrays

 
 
ucfcpegirl06
Guest
Posts: n/a
 
      09-25-2006
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?

 
Reply With Quote
 
 
 
 
Daniel T.
Guest
Posts: n/a
 
      09-25-2006
"ucfcpegirl06" <(E-Mail Removed)> wrote:

> 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.
 
Reply With Quote
 
 
 
 
Jerry Coffin
Guest
Posts: n/a
 
      09-27-2006
In article <(E-Mail Removed) om>,
http://www.velocityreviews.com/forums/(E-Mail Removed) 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<line> lines;

std::ifstream infile("file");

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

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

--
Later,
Jerry.

The universe is a figment of its own imagination.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multidimensional arrays and arrays of arrays Philipp Java 21 01-20-2009 08:33 AM
c++ primer statement about vectors containing vectors pauldepstein@att.net C++ 3 03-26-2008 06:22 PM
Ruby, SWIG and C++: how to properly wrap vector of vectors of doubles (2D vectors)? Ruby 0 09-14-2005 05:47 PM
Re: looping through arrays vs. vectors Frank Java 1 08-05-2003 11:44 AM
Re: looping through arrays vs. vectors VisionSet Java 1 08-05-2003 06:21 AM



Advertisments