Hey guys, I'm a beginner at this C++ stuff..and I've got a question. My assignment is to create a class called "students" and create with my secondary code(not my driver code) an array in which to store, display, sort, and then re-display the information. I am, however, confused as to how to create an array within my secondary code. Here are my three files(driver first, then class, then secondary code). The particular problem I'm running into is this: I keep getting a "error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::basic_istream<_Elem,_Traits>' (or there is no acceptable conversion)" error for the "in >> id[n] .... line of my secondary code. Is this the correct way to set up and work with an array within my code? Thanks for the help!!
/*******************************
*Student Program
*Written By Daren Baker
*11-17-2010
*******************************/
#include<iostream>
#include<iomanip>
#include<string>
#include<fstream>
#include<string>
using namespace std;
#include "students.h"
//Main driver code
void main()
{string file;
class students;
int id;
fstream a;
//Header display
cout << "Student Records Retriever" << endl;
//Source file retrieval
cout << "Enter source file name: ";
cin >> file;
//Open file
a.open(file.data(),ios::in);
//Call get function
a.get();
}
class students
#define MAX 100
{ public:
students(); //Constructor-empty
bool get(istream &); //Collects data from istream
void put(ostream &); //Displays student data
void operator > (students); //Last name greater than comparator
void operator < (students); //Last name less than comparator
void operator == (students); //Last name equality comparator
bool operator == (int id); //Compares inputted ID to records
private:
string first[MAX],last[MAX];
int id[MAX],age[MAX];
float gpa[MAX];
};
/****************************
*Student data manip. code
****************************/
#include<fstream>
#include<iostream>
Also, don't do what you're doing for first/last name, you'll likely be docked marks for it. The ">>" operator only gets stuff up to the first space (space is the default delimiter), meaning that if the first or last name contains a space it will break things (badly at that, all the data will be shifted over by one and all subsequent records will be corrupted). You can use std::getline(stream, destination, delim), to begin solving that problem.