I'm having trouble writing it out. To write it out I have this:
Code:
cout << States [row] << AdmNum [row];
The code for opening and closing the file is this:
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
const int ROW_MAX = 1; //I should have 50 rows, however, when I use 50 the file I read is all messed up
ifstream &GetString (ifstream&, string&, const int, const char = '\n');
int main()
{
string States [ROW_MAX];
int AdmNum [ROW_MAX];
int RowsUsed;
string InFile;
ifstream datafile;
cout << "Enter the name of the date file containing information\nabout some of the United States : ";
cin >> InFile;
cin.ignore (100, '\n');
cout << endl;
datafile.open(InFile.c_str());
if (!datafile)
cout << "\nThe file could not be opened for reading.\n";
else
{
RowsUsed = 0;
GetString (datafile, InFile, 15); //I have a function for this
while (!datafile.eof() && RowsUsed < ROW_MAX)
{
States [RowsUsed] = InFile;
for ( int row = 0; row < ROW_MAX; row++)
{
States [row] = InFile;
datafile.ignore (21, '\n');
datafile >> AdmNum [row];
datafile.ignore (2000, '\n');
cout << States [row] << AdmNum [row];
GetString (datafile, InFile, 15);
}
}
}
datafile.close();