Using Vectors vs. Arrays

Discussion in 'C++' started by ucfcpegirl06, Sep 25, 2006.

  1. ucfcpegirl06

    ucfcpegirl06 Guest

    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?
    ucfcpegirl06, Sep 25, 2006
    #1
    1. Advertising

  2. ucfcpegirl06

    Daniel T. Guest

    "ucfcpegirl06" <> 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-lite/operator-overloading.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.
    Daniel T., Sep 25, 2006
    #2
    1. Advertising

  3. ucfcpegirl06

    Jerry Coffin Guest

    In article <>,
    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.
    Jerry Coffin, Sep 27, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VisionSet
    Replies:
    1
    Views:
    430
    Weasel
    Aug 5, 2003
  2. Frank
    Replies:
    1
    Views:
    2,469
    Neomorph
    Aug 5, 2003
  3. Replies:
    3
    Views:
    685
    Shadowman
    Mar 26, 2008
  4. Philipp
    Replies:
    21
    Views:
    1,111
    Philipp
    Jan 20, 2009
  5. Guest
    Replies:
    0
    Views:
    431
    Guest
    Sep 14, 2005
Loading...

Share This Page