Having Trouble

Okay guys and gals here is a code I am having trouble with maybe someone can help me please!



    #include <iostream>
    #include <fstream>
     
    using namespace std;
     
    const int maxRows = 5, maxCols = 6;
    void readNames(string seats[ ][maxCols]);
    void display(string seats[ ][maxCols]);
    void switchStudents(string seats[ ][maxCols]);
     
    int main( )
      {
        int choice;
        string seats[maxRows][maxCols];
        readNames(seats);
        bool finished = false;
        cout << "Seating Chart Program " << endl;
        while (!finished)
          {
            cout << "1 - Display the Seating Chart" << endl;
            cout << "2 - Switch 2 students" << endl;
            cout << "3 - Quit" << endl << endl;
     
            cout << "Enter your choice (1-3): ";
            cin >> choice;
     
            switch (choice)
              {
                case 1: display(seats); break;
                case 2: switchStudents(seats); break;
                case 3: finished = true; break;
                default: cout << "incorrect response. Please reenter";
              }
          }
        system("pause");
        return 0;
        }
     
    void readNames(string seats[][6])
      {
        ifstream filein("C:\\seats.dat");
        for (int row = 0; row< maxRows; row++)
            for (int col = 0; col< maxCols; col++)
                filein >> seats[row][col];
        filein.close( );
        }
     
    void display(string seats[ ][6])
      {
        cout << "\n 0 1 2 3 4 5\n";
        for ( int r = 0; r < maxRows; r++)
          {
            cout << r << " ";
            for (int col = 0; col < maxCols; col++)
              {
                cout.width(12);
                cout.setf(ios::left);
                cout << seats[r][col];
              }
            cout << endl;
          }
        cout << endl << endl;
      }
     
    void switchStudents(string seats[][6])
      {
        int r1, c1, r2, c2;
        cout << "\nEnter row & col for first student: ";
        cin>> r1 >> c1;
        cout << "\nEnter row & col for second student: ";
        cin >> r2 >> c2;
        string temp = seats[r1][c1];
        seats[r1][c1] = seats[r2][c2];
        seats[r2][c2] = temp;
     
    }


The problem I am having is with this part of the code I don't know what to do.
filein >> seats[row][col];
@Dark3nd

You just need to add #include <string> to your list of includes, and the program should work, since seats is declared as a string array.
Last edited on
Topic archived. No new replies allowed.