Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to skip columns while reading input txt to array?

Zheung YikZheung Yik Member Posts: 1
edited December 1 in Beginner C/C++

This is my text file

1 2 3 4 5 New York
1 3 5 4 6 Jersey City
1 3 5 2 5 Los Angeles
1 3 5 1 3 Santa Monica

My code

int main()
{
const int row=4;
const int col=7;
int numbers[row][col];
string town[row];
ifstream in;

in.open("input.txt");

for(int i=0; i<row; i++)
{
    for (int j=0; j<col; j++)
    {
        in>>numbers[i][j];

        if(j==6)
        {
            in>>town[i];
        }
    }
}
cout<<numbers[0][2];
cout<<town[0];

return 0;
}

I want to put the numbers into 2d array and store the city names into 1d array. However, I can only get the 2d array to work. It does not display the place names.... Can somebody help me?

Sign In or Register to comment.