I understand that with this question there are already several messages on the network. However, the answers do not help me :( Can anyone help me? I have quite a few classes, but these errors do not apply to all of them. These errors occurred “accidentally”, and I have no idea where I'm starting to look .
The solutions I tried but did not help:
- including precompiled stdafx.h header file
#include pragma once- did everything
ifndefas welldefine
In addition, I also get strange errors, for example:
Error 507 error C2275: '_iobuf' : illegal use of this type as an expression
as well as many other syntax errors.
I have 10.h and .cpp files, so I just copied the paste 2 pairs of them that have the errors mentioned above. Can someone help me with this please? Thank!
// file storage.h
#pragma once
#ifndef STORAGE_H
#define STORAGE_H
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include "settings.h"
#include "Catalogue.h"
#include "paymentModeList.h"
#include "user.h"
using namespace std;
class Storage
{
private:
static const string KEYWORD_USERNAME;
static const string KEYWORD_PASSWORD;
static const string KEYWORD_ACCTALERT;
static const string KEYWORD_PAYMENTALERT;
static const string KEYWORD_ITEMALERT;
static const string KEYWORD_TITLENAME;
static const string KEYWORD_CATLINES;
static const string KEYWORD_ITEMNAME;
static const string KEYWORD_PRICE;
static const string KEYWORD_PAYMENTMODE;
static const string KEYWORD_PAYMENTACCOUNT;
static const string KEYWORD_CATEGORY;
static const string KEYWORD_DATE;
static const string KEYWORD_REMARKS;
static const string KEYWORD_ONNOTIFICATIONS;
static const string KEYWORD_PAIDSTATUS;
static const string KEYWORD_DAYSBEFORE;
public:
Storage();
vector<User*> getVectorUser();
vector<Catalogue*> getCatalogueList(int);
vector<Item*> getNotificationList(int);
vector<PaymentMode*> getPaymentModeList(int);
Settings* getSettings(int);
void writeVectorUser(vector<User*>);
void writeCatalogueList(vector<Catalogue*>, int);
void writeNotificationList(vector<Item*>, int);
void writeSettings(Settings*, int);
void writePaymentModeList(vector<PaymentMode*>, int);
string getTaskInfo(string& task, string infoStart, string infoEnd);
bool checkEmpty(ifstream &readFile);
};
#endif
// user.h file
#pragma once
#ifndef _USER_H
#define _USER_H
#include <string>
#include <iostream>
#include "item.h"
#include "account.h"
#include "accountList.h"
#include "settings.h"
#include "paymentModeList.h"
#include "NotificationList.h"
#include "catalogueList.h"
using namespace std;
class User
{
private:
string username;
string password;
int user_index;
public:
User(string, string, int);
string GetUsername();
string GetPassword();
void makeSettings(string, string);
Settings* makeSettings(string, string, bool, bool, bool);
void enterSettings(Settings*, PaymentModeList*, AccountList*);
void enterUser();
void addExpenses(CatalogueList*, NotificationList*, PaymentModeList*, AccountList*);
void deleteEdit(CatalogueList*, NotificationList*);
void deleteCategory(string, CatalogueList*, NotificationList*);
void retrieve(CatalogueList*, NotificationList*, PaymentModeList*, AccountList*);
void viewSummary(Settings*, PaymentModeList*, AccountList*);
};
#endif
//user.cpp
#include "user.h"
using namespace std;
User :: User(string givenUser, string givenPassword, int index)
{
username = givenUser;
password = givenPassword;
user_index = index;
}
string User :: GetUsername()
{
return username;
}
string User :: GetPassword()
{
return password;
}
Settings* User :: makeSettings(string user, string pass, bool paymentAlert, bool accountAlert, bool itemAlert)
{
Settings* mySettings = new Settings(user, pass, paymentAlert, accountAlert, itemAlert);
return mySettings;
}
void User :: enterUser()
{
CatalogueList* myCatalogueList = new CatalogueList();
NotificationList* myNotificationList = new NotificationList();
Settings* mySettings = new Settings(username, password, true, true, true);
PaymentModeList* myPayModeList = new PaymentModeList();
AccountList* myAcctList = new AccountList();
enterSettings(mySettings, myPayModeList, myAcctList);
addExpenses(myCatalogueList, myNotificationList, myPayModeList, myAcctList);
viewSummary(mySettings,myPayModeList, myAcctList);
return;
}
void User :: addExpenses(CatalogueList* myCL, NotificationList* myNL, PaymentModeList* myPL, AccountList* myAL)
{
string itemName;
double price;
string paymentMode;
string account;
string category;
int date;
string remarks;
bool onNotification;
bool paidStatus;
int daysBefore;
cin >> itemName >> price >> paymentMode >> account >> category >> date >> remarks >> onNotification >> paidStatus >> daysBefore;
Item* itemToAdd = new Item(itemName, price, paymentMode, account, category, date, remarks, onNotification, paidStatus, daysBefore);
(*myCL).addItem(itemToAdd);
Account* toAddAcct = new Account(account);
PaymentMode* toAddPayMode = new PaymentMode(paymentMode);
int indexAcct = (*myAL).findAcct(toAddAcct);
if(indexAcct == -1)
(*myAL).addAcct(toAddAcct);
vector<Account*> tempVA = (*myAL).getVectorAcctList();
(*tempVA[indexAcct]).addPayMode(toAddPayMode);
int indexPM = (*myPL).findPaymentMode(toAddPayMode);
if( indexPM == -1 )
(*myPL).addPaymentMode(toAddPayMode);
vector<PaymentMode*> tempVPM = (*myPL).getVectorPayModeList();
(*tempVPM[indexPM]).addAcct(toAddAcct);
(*(tempVA[indexAcct])).updateAcctBal(price);
(*(tempVPM[indexPM])).updatePayModeBal(price);
if( (onNotification == true) && ( (*myNL).findItem(itemToAdd) == -1) )
(*myNL).addItem(itemToAdd);
return;
}
void User:: enterSettings(Settings* mySettings, PaymentModeList* myPL, AccountList* myAL)
{
(*mySettings).changeUsername();
(*mySettings).changePassword();
string toFindAcct;
cin >> toFindAcct;
Account* tempA = new Account(toFindAcct);
int indexA = (*myAL).findAcct(tempA);
double newAcctThreshold;
cin >> newAcctThreshold;
vector<Account*> tempVA = (*myAL).getVectorAcctList();
(*tempVA[indexA]).setAccountThreshold(newAcctThreshold);
string toFindPM;
cin >> toFindPM;
PaymentMode* tempPM = new PaymentMode(toFindPM);
int indexP = (*myPL).findPaymentMode(tempPM);
double newPMThreshold;
cin >> newPMThreshold;
vector<PaymentMode*> tempVPM = (*myPL).getVectorPayModeList();
(*tempVPM[indexP]).setPaymentModeThreshold(newPMThreshold);
(*mySettings).toggleBudgetAlert();
(*mySettings).toggleRepeatedItemsNotification();
}
void User :: viewSummary(Settings* mySet, PaymentModeList* myPL, AccountList* myAL)
{
string userN = (*mySet).getUsername();
cout << userN << endl;
double sumAcctBal = (*myAL).getSumOfAllAcctBal();
cout << sumAcctBal;
double sumPayModeBal = (*myPL).getSumOfAllPayModeBal();
cout << sumPayModeBal << endl;
}
void User :: retrieve(CatalogueList* myCL, NotificationList* myNL, PaymentModeList* myPL, AccountList* myAL)
{
vector< vector<Item*> > retrieveOutput;
string itemName;
string paymentMode;
string account;
string category;
string date;
double price;
cin >> itemName;
retrieveOutput = (*myCL).retrieveItem(itemName);
cin >> paymentMode;
vector<Catalogue*> catList = (*myCL).getVCatList();
for(int i = 0; i < catList.size(); i++)
{
return;
}
}
//storage.cpp
#include "storage.h"
using namespace std;
const string Storage::KEYWORD_USERNAME = " -username ";
const string Storage::KEYWORD_PASSWORD = " -password ";
const string Storage::KEYWORD_ACCTALERT = " -acctAlert ";
const string Storage::KEYWORD_PAYMENTALERT = " -payModeAlert ";
const string Storage::KEYWORD_ITEMALERT = " -itemAlert ";
const string Storage::KEYWORD_TITLENAME = " -titlename ";
const string Storage::KEYWORD_CATLINES = " -catlines ";
const string Storage::KEYWORD_ITEMNAME = " -itemname ";
const string Storage::KEYWORD_PRICE = " -price ";
const string Storage::KEYWORD_PAYMENTMODE = " -paymentmode ";
const string Storage::KEYWORD_PAYMENTACCOUNT = " -paymentaccount ";
const string Storage::KEYWORD_CATEGORY = " -category ";
const string Storage::KEYWORD_DATE = " -date ";
const string Storage::KEYWORD_REMARKS = " -remarks ";
const string Storage::KEYWORD_ONNOTIFICATIONS = " -onNotifications ";
const string Storage::KEYWORD_PAIDSTATUS = " -paidstatus ";
const string Storage::KEYWORD_DAYSBEFORE = " -daysbefore ";
Storage :: Storage()
{}
bool Storage :: checkEmpty(ifstream &readFile)
{
if(readFile.is_open())
{
if(readFile.peek() == std::ifstream::traits_type::eof())
return true;
else
return false;
}
else
return false;
}
string Storage::getTaskInfo(string& task, string infoStart, string infoEnd)
{
int startPos = 0, endPos = 0;
if(!infoStart.empty())
{
startPos = task.find(infoStart);
if(startPos == string::npos)
return "";
startPos += infoStart.length();
}
endPos = task.rfind(infoEnd);
if(endPos == string::npos)
return task.substr(startPos).c_str();
return task.substr(startPos, endPos-startPos).c_str();
}
vector<User*> Storage :: getVectorUser()
{
vector<User*> userList;
ifstream readFile("userInformation.txt");
string oneUser;
string username;
string password;
int index =0;
while(!checkEmpty(readFile))
{
getline(readFile, oneUser);
username = getTaskInfo(oneUser, "", KEYWORD_USERNAME);
password = getTaskInfo(oneUser, "", KEYWORD_PASSWORD);
User* toAdd = new User(username, password, index);
userList.push_back(toAdd);
index++;
}
return userList;
}
void Storage :: writeVectorUser(vector<User*> allMyUsers)
{
ofstream storeFile;
storeFile.open("userInformation.txt");
for(int i=0; i<allMyUsers.size(); i++)
{
string username = allMyUsers[i] -> GetUsername();
string password = allMyUsers[i] -> GetPassword();
storeFile << username
<< KEYWORD_USERNAME
<< password
<< KEYWORD_PASSWORD
<< endl;
}
storeFile.close();
return;
}
vector<Item*> Storage :: getNotificationList(int index)
{
string finalName = "notificationInfo";
string indexName;
ostringstream convert;
convert << index;
indexName = convert.str() + ".txt";
finalName = finalName + indexName;
char* cstr_fileName = new char[finalName.length() + 1];
strcpy(cstr_fileName, finalName.c_str());
ifstream readFile(cstr_fileName);
string oneItem;
string itemname;
string price;
string paymentMode;
string paymentAccount;
string category;
string date;
string remarks;
string onNotifications;
string paidStatus;
string daysBefore;
vector<Item*> notifyList;
while(!checkEmpty(readFile))
{
getline(readFile, oneItem);
itemname = getTaskInfo(oneItem, "", KEYWORD_ITEMNAME);
price = getTaskInfo(oneItem, "", KEYWORD_PRICE);
double price_double = atof(price.c_str());
paymentMode = getTaskInfo(oneItem, "", KEYWORD_PAYMENTMODE);
paymentAccount = getTaskInfo(oneItem, "", KEYWORD_PAYMENTACCOUNT);
category = getTaskInfo(oneItem, "", KEYWORD_CATEGORY);
date = getTaskInfo(oneItem, "", KEYWORD_DATE);
int date_int = atoi(date.c_str());
remarks = getTaskInfo(oneItem, "", KEYWORD_REMARKS);
onNotifications = getTaskInfo(oneItem, "", KEYWORD_ONNOTIFICATIONS);
bool onNotify_bool;
if(onNotifications == "true")
onNotify_bool = true;
else
onNotify_bool = false;
paidStatus = getTaskInfo(oneItem, "", KEYWORD_PAIDSTATUS);
bool paidStatus_bool;
if(paidStatus == "true")
paidStatus_bool = true;
else
paidStatus_bool = false;
daysBefore = getTaskInfo(oneItem, "", KEYWORD_DAYSBEFORE);
int daysBefore_int = atoi(daysBefore.c_str());
Item* itemAdd = new Item(itemname, price_double, paymentMode, paymentAccount, category, date_int, remarks, onNotify_bool, paidStatus_bool, daysBefore_int);
notifyList.push_back(itemAdd);
}
return notifyList;
}
void Storage :: writeNotificationList(vector<Item*> notifyList, int index)
{
string finalName = "notificationInfo";
string indexName;
ostringstream convert;
convert << index;
indexName = convert.str() + ".txt";
finalName = finalName + indexName;
char* cstr_fileName = new char[finalName.length() + 1];
strcpy(cstr_fileName, finalName.c_str());
ofstream storeFile;
storeFile.open(cstr_fileName);
for(int j=0; j<notifyList.size(); j++)
{
string itemname = notifyList[j] -> getName();
double price = notifyList[j] -> getPrice();
int priceInCents = price * 100;
ostringstream convertPrice;
convertPrice << priceInCents;
string price_str = convertPrice.str();
string paymentmode = notifyList[j] -> getPaymentMode();
string paymentaccount = notifyList[j] -> getPaymentAccount();
string category = notifyList[j] -> getCat();
int date = notifyList[j] -> getDate();
ostringstream convertDate;
convertDate << date;
string date_str = convertDate.str();
string remarks = notifyList[j] -> getRemarks();
bool onNotification = notifyList[j] -> getNotification();
string onNotification_str;
if(onNotification == true)
onNotification_str = "true";
else
onNotification_str = "false";
bool paidstatus = notifyList[j] -> getPaidStatus();
string paidStatus_str;
if(paidstatus == true)
paidStatus_str = "true";
else
paidStatus_str = "false";
int daysbefore = notifyList[j] -> getDaysBefore();
ostringstream convertDaysBefore;
convertDaysBefore << daysbefore;
string daysbefore_str = convertDaysBefore.str();
storeFile << itemname
<< KEYWORD_ITEMNAME
<< price_str
<< KEYWORD_PRICE
<< paymentmode
<< KEYWORD_PAYMENTMODE
<< paymentaccount
<< KEYWORD_PAYMENTACCOUNT
<< category
<< KEYWORD_CATEGORY
<< date_str
<< KEYWORD_DATE
<< remarks
<< KEYWORD_REMARKS
<< onNotification_str
<< KEYWORD_ONNOTIFICATIONS
<< paidStatus_str
<< KEYWORD_PAIDSTATUS
<< daysbefore_str
<< KEYWORD_DAYSBEFORE
<< endl;
}
storeFile.close();
return;
}
void Storage :: writeSettings(Settings* mySettings, int index)
{
string finalName = "settingsInfo";
string indexName;
ostringstream convert;
convert << index;
indexName = convert.str() + ".txt";
finalName = finalName + indexName;
char* cstr_fileName = new char[finalName.length() + 1];
strcpy(cstr_fileName, finalName.c_str());
ofstream storeFile;
storeFile.open(cstr_fileName);
string username = mySettings -> getUsername;
string password = mySettings -> getPassword;
bool onAcctBudgetAlert = mySettings -> getOnAcctBudgetAlert;
string onAcctBudgetAlert_str;
if(onAcctBudgetAlert == true)
onAcctBudgetAlert_str = "true";
else
onAcctBudgetAlert_str = "false";
bool onPayModeBudgetAlert = mySettings -> getOnPayModeBudgetAlert;
string onPayModeBudgetAlert_str;
if(onPayModeBudgetAlert == true)
onPayModeBudgetAlert_str = "true";
else
onPayModeBudgetAlert_str = "false";
bool onRepeatedItemsNotification = mySettings -> getOnRepeatedItemsNotification;
string onRepeatedItemsNotification_str;
if(onRepeatedItemsNotification == true)
onRepeatedItemsNotification_str = "true";
else
onRepeatedItemsNotification_str = "false";
storeFile << username
<< KEYWORD_USERNAME
<< password
<< KEYWORD_PASSWORD
<< onAcctBudgetAlert_str
<< KEYWORD_ACCTALERT
<< onPayModeBudgetAlert_str
<< KEYWORD_PAYMENTALERT
<< onRepeatedItemsNotification_str
<< KEYWORD_ITEMALERT
<< endl;
storeFile.close();
return;
}
vector<Catalogue*> Storage :: getCatalogueList(int index)
{
vector<Catalogue*> catList;
string finalName = "catalogueInfo";
string indexName;
ostringstream convert;
convert << index;
indexName = convert.str() + ".txt";
finalName = finalName + indexName;
char* cstr_fileName = new char[finalName.length() + 1];
strcpy(cstr_fileName, finalName.c_str());
ifstream readFile(cstr_fileName);
string oneCat;
string titlename;
string catlines;
int catlines_int;
string oneItem;
string itemname;
string price;
string paymentMode;
string paymentAccount;
string category;
string date;
string remarks;
string onNotifications;
string paidStatus;
string daysBefore;
while(!checkEmpty(readFile))
{
getline(readFile, oneCat);
titlename = getTaskInfo(oneCat, "", KEYWORD_TITLENAME);
catlines = getTaskInfo(oneCat, "", KEYWORD_CATLINES);
Catalogue* CatAdd = new Catalogue(titlename);
catlines_int = atoi(catlines.c_str());
for(int i=0; i<catlines_int; i++)
{
getline(readFile, oneItem);
itemname = getTaskInfo(oneItem, "", KEYWORD_ITEMNAME);
price = getTaskInfo(oneItem, "", KEYWORD_PRICE);
double price_double = atof(price.c_str());
paymentMode = getTaskInfo(oneItem, "", KEYWORD_PAYMENTMODE);
paymentAccount = getTaskInfo(oneItem, "", KEYWORD_PAYMENTACCOUNT);
category = getTaskInfo(oneItem, "", KEYWORD_CATEGORY);
date = getTaskInfo(oneItem, "", KEYWORD_DATE);
int date_int = atoi(date.c_str());
remarks = getTaskInfo(oneItem, "", KEYWORD_REMARKS);
onNotifications = getTaskInfo(oneItem, "", KEYWORD_ONNOTIFICATIONS);
bool onNotify_bool;
if(onNotifications == "true")
onNotify_bool = true;
else
onNotify_bool = false;
paidStatus = getTaskInfo(oneItem, "", KEYWORD_PAIDSTATUS);
bool paidStatus_bool;
if(paidStatus == "true")
paidStatus_bool = true;
else
paidStatus_bool = false;
daysBefore = getTaskInfo(oneItem, "", KEYWORD_DAYSBEFORE);
int daysBefore_int = atoi(daysBefore.c_str());
Item* itemAdd = new Item(itemname, price_double, paymentMode, paymentAccount, category, date_int, remarks, onNotify_bool, paidStatus_bool, daysBefore_int);
CatAdd -> pushItem(itemAdd);
}
catList.push_back(CatAdd);
}
return catList;
}
void Storage :: writeCatalogueList(vector<Catalogue*> catList, int index)
{
string finalName = "catalogueInfo";
string indexName;
ostringstream convert;
convert << index;
indexName = convert.str() + ".txt";
finalName = finalName + indexName;
char* cstr_fileName = new char[finalName.length() + 1];
strcpy(cstr_fileName, finalName.c_str());
ofstream storeFile;
storeFile.open(cstr_fileName);
for(int i=0; i<catList.size(); i++)
{
vector<Item*> itemCat = catList[i] -> getVCatItems();
string titleName = catList[i] -> getCatName();
int catLines = itemCat.size();
ostringstream convertCatLines;
convertCatLines << catLines;
string catLines_str = convertCatLines.str();
storeFile << titleName
<< KEYWORD_TITLENAME
<< catLines_str
<< KEYWORD_CATLINES
<< endl;
for(int j=0; j<itemCat.size(); j++)
{
string itemname = itemCat[j] -> getName();
double price = itemCat[j] -> getPrice();
int priceInCents = price * 100;
ostringstream convertPrice;
convertPrice << priceInCents;
string price_str = convertPrice.str();
string paymentmode = itemCat[j] -> getPaymentMode();
string paymentaccount = itemCat[j] -> getPaymentAccount();
string category = itemCat[j] -> getCat();
int date = itemCat[j] -> getDate();
ostringstream convertDate;
convertDate << date;
string date_str = convertDate.str();
string remarks = itemCat[j] -> getRemarks();
bool onNotification = itemCat[j] -> getNotification();
string onNotification_str;
if(onNotification == true)
onNotification_str = "true";
else
onNotification_str = "false";
bool paidstatus = itemCat[j] -> getPaidStatus();
string paidStatus_str;
if(paidstatus == true)
paidStatus_str = "true";
else
paidStatus_str = "false";
int daysbefore = itemCat[j] -> getDaysBefore();
ostringstream convertDaysBefore;
convertDaysBefore << daysbefore;
string daysbefore_str = convertDaysBefore.str();
storeFile << itemname
<< KEYWORD_ITEMNAME
<< price_str
<< KEYWORD_PRICE
<< paymentmode
<< KEYWORD_PAYMENTMODE
<< paymentaccount
<< KEYWORD_PAYMENTACCOUNT
<< category
<< KEYWORD_CATEGORY
<< date_str
<< KEYWORD_DATE
<< remarks
<< KEYWORD_REMARKS
<< onNotification_str
<< KEYWORD_ONNOTIFICATIONS
<< paidStatus_str
<< KEYWORD_PAIDSTATUS
<< daysbefore_str
<< KEYWORD_DAYSBEFORE
<< endl;
}
}
storeFile.close();
return;
}