C++ 错误C2653:&x27;用户';:不是类或命名空间名称
我知道网上已经有好几篇关于这个问题的帖子了。然而,答案对我没有帮助:(有人能帮我吗?我有很多课,但这些错误并不适用于所有的课。这些错误有点“随机”出现,我不知道从哪里开始看 我尝试过但无济于事的解决方案:C++ 错误C2653:&x27;用户';:不是类或命名空间名称,c++,visual-c++,visual-studio-2012,C++,Visual C++,Visual Studio 2012,我知道网上已经有好几篇关于这个问题的帖子了。然而,答案对我没有帮助:(有人能帮我吗?我有很多课,但这些错误并不适用于所有的课。这些错误有点“随机”出现,我不知道从哪里开始看 我尝试过但无济于事的解决方案: 包括预编译头文件stdafx.h #包含pragma一次 是否所有的ifndef以及都定义了 此外,我也会遇到一些奇怪的错误,比如: Error 507 error C2275: '_iobuf' : illegal use of this type as an expression
#包含pragma一次
ifndef
以及都定义了
Error 507 error C2275: '_iobuf' : illegal use of this type as an expression
以及许多其他语法错误
我喜欢10.h和.cpp文件,所以我只复制了2对上面提到的错误。有人能帮我吗?谢谢
//存储.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:
//for userInformation.txt
static const string KEYWORD_USERNAME;
static const string KEYWORD_PASSWORD;
//for settingsInfo.txt
static const string KEYWORD_ACCTALERT;
static const string KEYWORD_PAYMENTALERT;
static const string KEYWORD_ITEMALERT;
//for catalogueInfo.txt
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;
//for paymentModeInfo.txt
//for accountInfo.txt
public:
Storage(); // empty constructor
//reading from files
vector<User*> getVectorUser();
vector<Catalogue*> getCatalogueList(int);
vector<Item*> getNotificationList(int);
//not done
vector<PaymentMode*> getPaymentModeList(int);
Settings* getSettings(int);
//writing to files
void writeVectorUser(vector<User*>);
void writeCatalogueList(vector<Catalogue*>, int);
void writeNotificationList(vector<Item*>, int);
void writeSettings(Settings*, int);
//not done
void writePaymentModeList(vector<PaymentMode*>, int);
//checking & misc
string getTaskInfo(string& task, string infoStart, string infoEnd);
bool checkEmpty(ifstream &readFile);
};
#endif
#pragma一次
#ifndef存储
#定义存储空间
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括“settings.h”
#包括“目录.h”
#包括“paymentModeList.h”
#包括“user.h”
使用名称空间std;
类存储
{
私人:
//对于userInformation.txt
静态常量字符串关键字\u用户名;
静态常量字符串关键字\u密码;
//用于设置sinfo.txt
静态常量字符串关键字\u ACCTALERT;
静态常量字符串关键字\u PAYMENTALERT;
静态常量字符串关键字\u ITEMALERT;
//对于catalogeinfo.txt
静态常量字符串关键字标题名;
静态常量字符串关键字\u CATLINES;
静态常量字符串关键字\u ITEMNAME;
静态常量字符串关键字\u价格;
静态常量字符串关键字\u PAYMENTMODE;
静态常量字符串关键字\u PAYMENTACCOUNT;
静态常量字符串关键字\u类别;
静态常量字符串关键字\u日期;
静态常量字符串关键字注释;
静态常量字符串关键字通知;
静态常量字符串关键字_PAIDSTATUS;
静态常量字符串关键字_DAYSBEFORE;
//对于paymentModeInfo.txt
//对于accountInfo.txt
公众:
Storage();//空构造函数
//从文件中读取
向量getVectorUser();
矢量目录列表(int);
向量getNotificationList(int);
//未完成
向量getPaymentModeList(int);
设置*getSettings(int);
//写入文件
无效writeVectorUser(向量);
void writeCalogueList(向量,int);
无效写化列表(向量,整数);
无效写入设置(设置*,int);
//未完成
void writePaymentModeList(向量,int);
//检查和杂项
string getTaskInfo(string&task、stringinfostart、stringinfoend);
bool checkEmpty(ifstream和readFile);
};
#恩迪夫
//user.h文件
#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;
//implement sorting method under private
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
#pragma一次
#ifndef\u用户\u H
#定义用户
#包括
#包括
#包括“项目h”
#包括“account.h”
#包括“accountList.h”
#包括“settings.h”
#包括“paymentModeList.h”
#包括“NotificationList.h”
#包括“目录列表h”
使用名称空间std;
类用户
{
私人:
字符串用户名;
字符串密码;
int用户索引;
//在私有模式下实现排序方法
公众:
用户(字符串、字符串、int);
字符串GetUsername();
字符串GetPassword();
void makeSettings(字符串、字符串);
设置*makeSettings(字符串、字符串、布尔、布尔、布尔);
无效输入设置(设置*、付款模式列表*、帐户列表*);
void enterUser();
作废附加费用(目录列表*、通知列表*、付款模式列表*、会计列表*);
作废删除编辑(目录列表*,通知列表*);
作废删除类别(字符串、目录列表*、通知列表*);
作废检索(目录列表*、通知列表*、付款模式列表*、会计列表*);
作废视图摘要(设置*、付款模式列表*、会计列表*);
};
#恩迪夫
//user.cpp
#包括“user.h”
使用名称空间std;
User::User(字符串givenUser、字符串givenPassword、int索引)
{
用户名=givenUser;
密码=给定密码;
用户索引=索引;
}
字符串用户::GetUsername()
{
返回用户名;
}
字符串用户::GetPassword()
{
返回密码;
}
//捷尔支付和会计警报
设置*用户::makeSettings(字符串用户、字符串传递、bool paymentAlert、bool accountAlert、bool itemAlert)
{
设置*mySettings=新设置(用户、通行证、paymentAlert、accountAlert、itemAlert);
返回我的设置;
}
void User::enterUser()
{
//一旦进入,用户需要构建所有列表,并将从数据库获取的数据存储到各自的位置
Catalogelist*MyCatalogelist=新目录列表();
NotificationList*myNotificationList=新建NotificationList();
Settings*mySettings=新设置(用户名、密码、true、true、true);//需要修改
PaymentModeList*MyPaymentModelist=new PaymentModeList();
AccountList*myAcctList=新AccountList();
//用户选择设置按钮
输入设置(mySettings、myPayModeList、myAcctList);
//用户选择添加按钮
增加费用(MyCatalogelist、myNotificationList、myPayModeList、myAcctList);
//用户选择摘要
查看摘要(mySettings、myPayModeList、myAcctList);
//用户选择检索
//检索(MyCatalogelist);
//用户选择删除/编辑
//删除编辑(我的目录列表);
//用户选择查看报告
//用户收到通知
//用户收到警报
//用户选择撤消
返回;
}
void User::addExpenses(目录列表*myCL,通知列表*myNL,付款模式列表*myPL,会计列表*myAL)
{
字符串itemName;
双倍价格;
字符串支付模式;
字符串帐户;
字符串类别;
国际日期;
字符串注释;
bool-onNotification;
布尔-派德状态;
国际日前;
//假设用户传递了正确的详细信息
cin>>项目名称>>价格>>
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;
}
//JIE ER PAYMENT AND ACCOUHNT ALERT
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()
{
//Once enter, user need to construct all the list and store data gotten from database to their respective location
CatalogueList* myCatalogueList = new CatalogueList();
NotificationList* myNotificationList = new NotificationList();
Settings* mySettings = new Settings(username, password, true, true, true); //NEED TO REVISE
PaymentModeList* myPayModeList = new PaymentModeList();
AccountList* myAcctList = new AccountList();
//user selects settings button
enterSettings(mySettings, myPayModeList, myAcctList);
//user select add button
addExpenses(myCatalogueList, myNotificationList, myPayModeList, myAcctList);
//user select summary
viewSummary(mySettings,myPayModeList, myAcctList);
//user select retrieve
//retrieve(myCatalogueList);
//user select delete/edit
//deleteEdit(myCatalogueList);
//user select viewReport
//user gets notification
//user gets alert
//user chooses undo
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;
//assume user pass in correct details
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);
//add to respective catalogue
(*myCL).addItem(itemToAdd);
//Create Account or PaymentMode if they are not existing
//update paymentModeList and accountList
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);
//Create Account or PaymentMode if they are not existing
//update paymentModeList and accountList
int indexPM = (*myPL).findPaymentMode(toAddPayMode);
if( indexPM == -1 )
(*myPL).addPaymentMode(toAddPayMode);
vector<PaymentMode*> tempVPM = (*myPL).getVectorPayModeList();
(*tempVPM[indexPM]).addAcct(toAddAcct);
//update balance at respective account
//find respective account
(*(tempVA[indexAcct])).updateAcctBal(price);
//update balance at respective paymetmode
//find respective paymentMode
(*(tempVPM[indexPM])).updatePayModeBal(price);
//add to notificationlist if necessary
if( (onNotification == true) && ( (*myNL).findItem(itemToAdd) == -1) ) //NEED TO REVISE FIND FUNCTION: Remarks
(*myNL).addItem(itemToAdd);
return;
}
void User:: enterSettings(Settings* mySettings, PaymentModeList* myPL, AccountList* myAL)
{
//user selects change username
(*mySettings).changeUsername();
//user selects change password
(*mySettings).changePassword();
//user selects to change Account Threshold
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);
//user selects to change PaymentMode Threshold
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);
//CENTRAL SWITCH FOR BUDGET_ALERT
//user selects change budgetAlert
(*mySettings).toggleBudgetAlert();
//CENTRAL SWITCH FOR NOTIFICATIONS
//user selects change repeated items notifications
(*mySettings).toggleRepeatedItemsNotification();
}
void User :: viewSummary(Settings* mySet, PaymentModeList* myPL, AccountList* myAL)
{
//display username
string userN = (*mySet).getUsername();
cout << userN << endl;
//display budget for account/paymentMode?
//display total expenditure by account
double sumAcctBal = (*myAL).getSumOfAllAcctBal();
cout << sumAcctBal;
//display total expenditure by paymentMode
double sumPayModeBal = (*myPL).getSumOfAllPayModeBal();
cout << sumPayModeBal << endl;
}
void User :: retrieve(CatalogueList* myCL, NotificationList* myNL, PaymentModeList* myPL, AccountList* myAL)
{
//user input any of the following itemName, price, paymentMode, account, category, date
//output the information for user to view
vector< vector<Item*> > retrieveOutput;
string itemName;
string paymentMode;
string account;
string category;
string date; //can be a range
double price;//can be a range
//Search by item name
cin >> itemName;
retrieveOutput = (*myCL).retrieveItem(itemName);
//search by paymentMode
cin >> paymentMode;
vector<Catalogue*> catList = (*myCL).getVCatList();
for(int i = 0; i < catList.size(); i++)
{
return;
}
}
/*void User :: deleteEdit(Expenses* myPriceList, Expenses* myCatalogueList)
{
string categoryToDelete;
cin >> categoryToDelete;
//user choose to delete by category
deleteCategory(categoryToDelete, myPriceList, myCatalogueList);
//*****user can choose to delete single or multiple items******////
//call for retrieve function
//user select items
//search through every list to delete the items
//*******user can choose to edit single item*******//
//call for retrieve function
//user select single item
//search through every list to edit the particular item*/
//return;
//}
/*
void User :: deleteCategory(string categoryToDelete, Expenses* myPriceList, Expenses* myCatalogueList)
{
myCatalogueList -> deleteCat(categoryToDelete);
myPriceList -> deleteCat(categoryToDelete);
return;
}
*/
#include "storage.h"
using namespace std;
//for userInformation.txt
const string Storage::KEYWORD_USERNAME = " -username ";
const string Storage::KEYWORD_PASSWORD = " -password ";
//for settings.txt
const string Storage::KEYWORD_ACCTALERT = " -acctAlert ";
const string Storage::KEYWORD_PAYMENTALERT = " -payModeAlert ";
const string Storage::KEYWORD_ITEMALERT = " -itemAlert ";
//for catalogueInfo.txt & notificationList.txt
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;
}