c++ - How do I skip the first line of an array when reading from a file? -


i'm trying read values text file , stick them array. text file i'm using this;

big stone gap,va red-tailed_hawk     1               mourning_dove       66               red-bellied_woodpecker  5               yellow-bellied_sapsucker 1              downy_woodpecker    4               pileated_woodpecker     2               blue_jay        8               american_crow       89              carolina_chickadee      8               black-capped_chickadee  6               tufted_titmouse     12              red-breasted_nuthatch   2               white-breasted_nuthatch  9              carolina_wren       3               american_robin      1               northern_mockingbird    1               european_starling   5               eastern_towhee      3               field_sparrow       13             fox_sparrow         1               song_sparrow        8               white-throated_sparrow  11             dark-eyed_junco     9              northern_cardinal   30             purple_finch        7               house_finch         6              american_goldfinch      29 

i'm trying read them array, , output array. have other stuff, (alter values user input), know how that. problem this; when run it, reads big , stone, , puts them values. isn't want; should red_tailed_hawk , 1. have code below; have no idea work right. please excuse of variables; cannibalized script project did int arrays instead of string arrays.

#include <iostream> #include <fstream> #include <iomanip>  using namespace std;  const int number_of_students = 28; const int number_of_scores = 28;  void getdata (ifstream& infile, string matrix[][number_of_scores + 1 ],                     int number_of_students) ;  void printmatrix(string matrix[][number_of_scores + 1], int number_of_students);    int main() { string birdarray [number_of_students][number_of_scores +1 ] ;               // column 0 hold student id.               // row n has id , birdarray student n.   ifstream indata; //input file stream variable indata.open("one.txt");  if ( !indata) {      cout << "invalid file name \n";       return 1; }  // input birdarray two-d array birdarray getdata ( indata , birdarray, number_of_students ); printmatrix(birdarray, number_of_students);    // return  row number of searchitem in particular column. // if not found, return -1 }   void getdata (ifstream& infile,string chart[][number_of_scores + 1 ],                     int student_count)  {  int row, col;    ( row = 0; row < student_count; row++)     (col =0; col <  number_of_scores +1  ; col++)         infile  >> chart [row] [col] ;   } void printmatrix(string matrix[][number_of_scores + 1], int number_of_students) { int row, col; //this code below loop displays values // (row = 0; row < number_of_students + 1; col++) // { //   cout << right << matrix[row][col];  //  cout << endl; //}  //this test code see if can output values right cout << matrix[0][2]; cout << matrix[0][3]; cout << matrix[0][4]; cout << matrix[0][5]; } 

string line;      getline(infile, line) ( row = 0; row < row_count; row++)         (col =0; col <  column_count +1  ; col++)             getline(infile, line);             chart[row][col] = line; 

streams behave namesake. can't skip comes in stream jumping through array, can ignore stuff floats by.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -