Perhaps someone can help me here. I have been looking over this code and I cannot figure why it is giving me an error(s). If someone can give me an alternative way I would greatly appreciate it.
The program is not entirely finished. The program is basically about classes which reads and writes into a datafile (pa8.dat).
Code:#include <string> #include <vector> #include <iostream.h> #include <iomanip.h> #include <stdio.h> #include <fstream.h> #include <stdlib.h> /**********************************base class REObject*******************/ class REObject { public: int block; //location var int lot; //location var float price; //price var int sq_footage; //duh virtual void Print(); //overridden in subclasses virtual void Write(); //overridden in subclasses private: }; //member methods - to be overridden! void REObject::Print() {cout<<"print REObject"<<endl;} void REObject::Write() {cout<<"write REObject"<<endl;} /**************** ONE FAMILYderived from REObject ***********************/ class OneFamily : public REObject { public: void Print(); //overridden void Write(); //overridden private: int bathrooms; int baths; int year_built; }; //member methods void OneFamily::Print() {cout<<"print OneFamily"<<endl;} void OneFamily::Write() {cout<<"write OneFamily"<<endl;} /**************** COMMERCIAL derived from REObject *************************/ class Commercial : public REObject { public: void Print(); //overridden void Write(); //overridden private: char type_of_commerce; bool sub_dividable; }; //member methods void Commercial::Print() {cout<<"print Commercial"<<endl;} void Commercial::Write() {cout<<"write Commercial"<<endl;} /***************** MULTIPLE DWEELING derived from REObject *******************/ class MultipleDwelling : public REObject { public: void Print(); //overridden void Write(); //overridden private: int num_of_units; }; //member methods void MultipleDwelling::Print() {cout<<"print MultipleDwelling"<<endl;} void MultipleDwelling::Write() {cout<<"write MultipleDwelling"<<endl;} /******************** REDBASE ************************/ class REDbase { public: REDbase(char *file); //constructor: get filename from th CLI, opens the file, //builds the dbase in an array of pointers... ~REDbase(); //destructor: writes the dbase back to file... void Add(); void Print(); void Save(); private: //vector<REObject*> dbase; //an array of REObject pointers (our database) REObject* dbase[100]; //array of pointers to REobjects char DataFile[50]; //data file name }; REDbase::REDbase(char *file) { ifstream ifdatafile; ifdatafile.open(file); if(!ifdatafile) { cout<<"Couldn't open dictionary. Exiting..."<<endl; exit(1); } string word; while(ifdatafile>>word) { //parse the datafile if(!strcmp(word.c_str(),"s")) { cout<<endl; cout<<"single dwelling: "; new OneFamily; } else if(!strcmp(word.c_str(),"m")) { cout<<endl; cout<<"multi dwelling :"; new MultipleDwelling; } else if(!strcmp(word.c_str(), "c")) { cout<<endl; cout<<"commercial :"; new Commercial; } else { cout<<" "<<word<<" "; } } cout<<endl; } /*******************************MAIN************************************************/ int main(int argc, char ** argv) { /* main calls class REObject member function constructor to open data file, parse the data and populate the database, filename is static! */ new REDbase("pa8.dat"); /* main the enters a UI loop, giving the option to add a listing, print all listings to the console, or saving the dbase to a file and then quitting the program. main determines the input and then calls member functions of REDbase accordingly */ return (0); }
The Error Message
Code:--------------------Configuration: pa8 - Win32 Debug-------------------- Compiling... pa8.cpp c:\documents and settings\val\desktop\c++\pa8.cpp(102) : error C2065: 'string' : undeclared identifier c:\documents and settings\val\desktop\c++\pa8.cpp(102) : error C2146: syntax error : missing ';' before identifier 'word' c:\documents and settings\val\desktop\c++\pa8.cpp(102) : error C2065: 'word' : undeclared identifier c:\documents and settings\val\desktop\c++\pa8.cpp(107) : error C2228: left of '.c_str' must have class/struct/union type c:\documents and settings\val\desktop\c++\pa8.cpp(113) : error C2228: left of '.c_str' must have class/struct/union type c:\documents and settings\val\desktop\c++\pa8.cpp(119) : error C2228: left of '.c_str' must have class/struct/union type Error executing cl.exe. pa8.obj - 6 error(s), 0 warning(s)
P.S I am using Visual C++ as the compiler.
Thanks.



LinkBack URL
About LinkBacks



Have a nice day.