I'm writing a code to display an array from a file, this is all done in a project with a .h file .cpp file and a main file. however my header file keeps giving me the error redefiniton of 'class token' and precious definition of 'class token' but I'm not very sure how to redefine it. thanks for help
main.cpp
using namespace std;
int main()
{
string filename;
int b;
int d;
int i;
int j;
token matrix[30][30];
cout << "Type the name of text file: e.g. 'File.txt'" << endl;
getline( cin, filename );//This could also be cin >> name//
matrix[30][30].setassign( filename );
cout << endl ;
system("pause") ;
}
token.h
// header file token.h
using namespace std;
class token
{
private:
string assignmat;
//char displaymat;
//char displaytoken;
public:
// Constructors
token();
token( string );
//token( string, char, char );
// Public functions
void setassign( string );
//void setdisplay( char );
//void settoken( char );
};`
token.cpp
using namespace std;
// constructor 1
token::token()
{
assignmat = " ";
//displaymat = ' ';
//displaytoken = ' ';
}
// constructor 2 parameterised constructor
token::token( string assignmat1) //, int displaymat1, char displaytoken1 )
{
assignmat = assignmat1;
//displaymat = displaymat1;
//displaytoken = displaytoken1;
}
// public function setName
void student::setassign( string filename )
{
char matrix[30][30];
ifstream inputFile;
int i,j;
inputFile.open(filename.c_str());
for(i = 0; i < b; i++)
{
for(j = 0; j < d; j++)
{
inputFile.get(matrix[i][j]);
if(matrix[i][j] == ',' || matrix[i][j] == '\n') // for some reason if i dont include the \n it doesnt work, but it should because the row ends at 30
{ //if loop to get rid of commas by deducting the counter by 1, hence replacing the comma with the next value
j-- ;
}
}
}
cout << endl;
for(i = 0; i < b; i++){ // display
for(j = 0; j < d; j++){
cout << " " << matrix[i][j] ;
}
cout << endl ;
}
}
sorry but i'm new on this forum and don't really know how to use it, I've also included the header files in my main file and .cpp file