Thank you laserlight. That helped me fix the including errors I had. One of my main questions is about the lines "myFile >> seperator;" I've used lines such as these in my other programs but in this one it complains "no match for 'operator>>' in 'myFile >> seperator' ". Is there something I'm doing wrong? And I've tried to code what I need in the end. I'm sure there are countless errors but maybe it would get the overall idea of what I'm trying to do.
Code:
void Set::readFromFile(std::ifstream& myFile)
{
int value;
char seperator;
myFile >> seperator; //remove {
if(! myFile.peek()=='}') //take in the first value
myFile >> value;
//take in the remaining values in the form ",value" repeating
while (! myFile.peek()=='}')
{
myFile >> seperator >> value;
insert(myList.getLength()+1,value);
}
myFile >> seperator; //remove }
}
Set Set::readOperator(std::ifstream& myFile)
{
Set b;
Set equal;
int value;
char seperator;
char operator;
myFile << operator; //take in the operator following }
b.readFromFile(myFile); //fill b with the set following the operator
if(operator == '+')
equal=this+b;
if(operator == '-')
equal=this-b;
if(operator == '*')
equal=this*b;
if(myFile.peek()=='+'||myFile.peek()=='-'||myFile.peek()=='*')
{
equal.readOperator(myFile);
}
else
{
return equal;
}
}
My driver uses it like this:
Code:
#include "Set.h"
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream myfile ("SetDoc.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
Set a;
Set result;
a.readFromFile(myFile);
result=a.readOperator(myFile);
result.displaySet();
}
myfile.close();
}
cin.get();
}