how to read tab delim file into 2D Array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yogi_bear_79

    how to read tab delim file into 2D Array

    I have a tab delimited file, that I want to read into a 2D array. I
    want to ignore the first two lines and the first colum of data.
  • Sashi Asokarajan

    #2
    Re: how to read tab delim file into 2D Array

    yogi_bear_79 wrote:
    I have a tab delimited file, that I want to read into a 2D array. I
    want to ignore the first two lines and the first colum of data.
    I would probably read the line with std::ifstream.g etline() using '\n' as delimiter
    into a std::string buffer and then split the string using std::stringstre am.getline()
    using '\t' as delimiter.

    sashi

    Comment

    • yogi_bear_79

      #3
      Re: how to read tab delim file into 2D Array

      I would probably read the line with std::ifstream.g etline() using '\n' as delimiter
      into a std::string buffer and then split the string using std::stringstre am.getline()
      using '\t' as delimiter.

      Ok, I can do that, but don't I have to declare the size of the array
      before I populate it? I have written the code to figure out how many
      rows and columns the text file contains. But I can not figure out a
      way to declare the array with non-constant variables?

      Comment

      • Obnoxious User

        #4
        Re: how to read tab delim file into 2D Array

        On Sat, 29 Mar 2008 15:29:59 -0700, yogi_bear_79 wrote:
        >I would probably read the line with std::ifstream.g etline() using '\n'
        >as delimiter into a std::string buffer and then split the string using
        >std::stringstr eam.getline() using '\t' as delimiter.
        >
        >
        Ok, I can do that, but don't I have to declare the size of the array
        before I populate it? I have written the code to figure out how many
        rows and columns the text file contains. But I can not figure out a way
        to declare the array with non-constant variables?
        Read about std::vector.

        --
        OU

        Comment

        • Thomas J. Gritzan

          #5
          Re: how to read tab delim file into 2D Array

          yogi_bear_79 wrote:
          >I would probably read the line with std::ifstream.g etline() using '\n' as delimiter
          >into a std::string buffer and then split the string using std::stringstre am.getline()
          >using '\t' as delimiter.
          >
          >
          Ok, I can do that, but don't I have to declare the size of the array
          before I populate it? I have written the code to figure out how many
          rows and columns the text file contains. But I can not figure out a
          way to declare the array with non-constant variables?
          Use std::vector<or similar, so you can add new rows, columns.

          --
          Thomas

          post tenebras lux. post fenestras tux.

          Comment

          • yogi_bear_79

            #6
            Re: how to read tab delim file into 2D Array

            >
            Read about std::vector.
            >
            ok, I Have created a 2D vector, where c=num of columns in my file, and
            r=num of rows. I've populated vectors from file before,using a while
            loop and pushback, but never a 2D. Below is sample data, basically
            the first row is useless, the second row starts with a null, then tab
            tehn Exam 1, tab etc.

            vector<stringv( c);
            vector<vector<s tring v2(r,v)

            This file contains the records of 20 students over 10 exams
            Exam1 Exam2 Exam3 Exam4 Exam5 Exam6 Exam7 Exam8 Exam9 Exam10
            Student1 90 100 89 75 88 99 100 87 88 85
            Student2 99 89 87 89 87 90 87 99 100 95

            Comment

            Working...