read and store text file as an array

This is a discussion on read and store text file as an array within the C++ Programming forums, part of the General Programming Boards category; Hello guys, I have a text file contains values such that the values are stored in the file as matrix ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    8

    read and store text file as an array

    Hello guys,
    I have a text file contains values such that the values are stored in the file as matrix of 3 by 4 dimension. i need to read this file and store each column of the matrix in a separate vector or in an array of one dimension.
    for example the values in a text file are:
    1 5 6 2
    0 8 4 6
    -1 7 9 3

    Can anyone offer a simple example please.

  2. #2
    Registered User
    Join Date
    Nov 2008
    Posts
    26
    You can use ifstream for an input file stream.

    1. To read an integer from a file stream, you can use extraction operator '>>'
    2. To push an element into a vector, you can use vector:ush_back method.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you help me about tolower() in file
    By nctar in forum C Programming
    Replies: 7
    Last Post: 05-12-2010, 10:04 AM
  2. Replies: 5
    Last Post: 08-01-2007, 06:17 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM
  5. Text file to 2D Array PLEASE HELP!
    By lostboy101 in forum C Programming
    Replies: 0
    Last Post: 03-26-2002, 09:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21