Hey guys, I need help figuring out where the problem with this program is. I am using an IDE(dev-c++) and I get a really odd message that I can't figure out. The message says :
"This application had requested the Runtime to terminate in an unusual way. Please contact the application's support team for more information."
Here's the main:
Code:#include <cstdlib> #include <iostream> #include <fstream> #include "CustomerData.h" using namespace std; int main(int argc, char *argv[]) { fstream file; file.open("test.txt", ios::in); while(!file.eof()){ CustomerData cd; try{ file>>cd; cout<<cd; }catch(string m){ cout<<m; }catch(...){ if(file.eof()) break; } } system("PAUSE"); return EXIT_SUCCESS; }
here's the header file:
Code://Creating a customer data class #include <iostream> #include <vector> #include <string> using namespace std; #ifndef __CUSTOMERDATA #define __CUSTOMERDATA class CustomerData; ostream &operator<<(ostream &ostr, CustomerData cd); istream &operator>>(istream &istr, CustomerData cd); class CustomerData{ private: string cusID, compName, ownerName, contactPos, contactName, address, city, state, zip, phone; public: string getCusID(); string getCompName(); string getOwnerName(); string getContactPos(); string getContactName(); string getAddress(); string getCity(); string getState(); string getZip(); string getPhone(); void setCusID(string)throw (string); void setCompName(string)throw (string); void setOwnerName(string, string)throw (string); void setContactPos(string)throw (string); void setContactName(string, string)throw (string); void setAddress(string)throw (string); void setCity(string)throw (string); void setState(string)throw (string); void setZip(string)throw (string); void setPhone(string)throw (string); CustomerData(); virtual ~CustomerData(); vector<string> vectorID; }; #endif
and the cpp file:
Code://Mike Webster //4.27.09 //CS 302 //Creating a customer data class #include "CustomerData.h" #include <iostream> #include <string> using namespace std; ostream &operator<<(ostream &ostr, CustomerData cd){ ostr<<cd.getCusID()<<endl; ostr<<cd.getCompName()<<endl; ostr<<cd.getOwnerName()<<endl; ostr<<cd.getContactPos()<<endl; ostr<<cd.getContactName()<<endl; ostr<<cd.getAddress()<<endl; ostr<<cd.getCity()<<endl; ostr<<cd.getState()<<endl; ostr<<cd.getZip()<<endl; ostr<<cd.getPhone()<<endl; return ostr; }; istream &operator>>(istream &istr, CustomerData cd){ string temp = ""; string temp2 = ""; char temp3[256]; istr>>temp; cd.setCusID(temp); temp = ""; istr>>temp; cd.setCompName(temp); temp = ""; istr>>temp; istr>>temp2; cd.setOwnerName(temp, temp2); temp = ""; istr.getline(temp3, 256); temp = temp3; cd.setContactPos(temp); temp = ""; istr>>temp; istr>>temp2; cd.setContactName(temp, temp2); temp = ""; istr>>temp; cd.setAddress(temp); temp = ""; istr>>temp; cd.setCity(temp); temp = ""; istr>>temp; cd.setState(temp); temp = ""; istr>>temp; cd.setZip(temp); temp = ""; istr>>temp; cd.setPhone(temp); temp = ""; return istr; }; CustomerData::CustomerData(){ setCusID("DEFAULT"); setCompName("DEFAULT"); setOwnerName("DEFAULT", "DEFAULT"); setContactPos("DEFAULT"); setContactName("DEFAULT","DEFAULT"); setAddress("DEFAULT"); setCity("DEFAULT"); setState("DF"); setZip("00000"); setPhone("(555)555-5555"); vectorID.clear(); }; void CustomerData::setCusID(string temp)throw (string){ bool flag = false; string temp2; for(int i = 0; i< vectorID.size(); i++){ if(vectorID[i]==temp) flag = true; } if(flag) throw("Non-Unique ID"); else if(temp.length()>12) throw("ID too long"); else if(temp.length()<2) throw("ID too short"); else cusID = temp; }; CustomerData::~CustomerData(){}; void CustomerData::setCompName(string temp)throw (string){ if(temp.length()>59) throw("CompName too long"); else if(temp.length()<1) throw("CompName too short"); else compName = temp; }; void CustomerData::setOwnerName(string temp, string temp2)throw (string){ if(temp.length() < 1 || temp2.length() < 1) throw("Incorrectly formatted owner Name"); else ownerName = temp; }; void CustomerData::setContactPos(string temp)throw (string){ if(temp.length()<1) throw("Nonexistent contact pos"); else contactPos = temp; }; void CustomerData::setContactName(string temp, string temp2)throw (string){ if(temp.length() < 1 || temp2.length() < 1) throw("Incorrectly Formatted ContactName"); else contactName = temp; }; void CustomerData::setAddress(string temp)throw (string){ if(temp.length() < 1) throw("Nonexistent Address"); else address = temp; }; void CustomerData::setCity(string temp)throw (string){ if(temp.length() < 1) throw("Nonexistent City"); else city = temp; }; void CustomerData::setState(string temp)throw (string){ if(temp.length() != 2) throw("Incorrectly Formatted State"); else state = temp; }; void CustomerData::setZip(string temp)throw (string){ if(temp.length() != 5) throw("Incorrectly Formatted Zipcode"); else zip = temp; }; void CustomerData::setPhone(string temp)throw (string){ if(temp.length() != 13) throw("Incorrectly Formatted Phone Number"); else phone = temp; }; string CustomerData::getCusID(){ return cusID; }; string CustomerData::getCompName(){ return compName; }; string CustomerData::getOwnerName(){ return ownerName; }; string CustomerData::getContactPos(){ return contactPos; }; string CustomerData::getContactName(){ return contactName; }; string CustomerData::getAddress(){ return address; }; string CustomerData::getCity(){ return city; }; string CustomerData::getState(){ return state; }; string CustomerData::getZip(){ return zip; }; string CustomerData::getPhone(){ return phone; };
Please help, I am really stuck on this one and my deadline is monday!
Any help is greatly appreciated!


Reply With Quote



Bookmarks