-2

我知道网上已经有好几篇关于这个问题的帖子了。但是,答案对我没有帮助:(有人能帮助我吗?我有很多课程,但这些错误并不适用于所有课程。这些错误有点“随机”出现,我不知道在哪里我开始看。

我尝试过但没有帮助的解决方案:

  1. 包括预编译的头文件 stdafx.h
  2. #include pragma once
  3. 尽善尽美ifndef_define

此外,我还会收到一些奇怪的错误,例如:

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

//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

//用户.cpp

#include “用户.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;
}

//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;
    }
    */

//存储.cpp

#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;
}
4

1 回答 1

4

以下是我在遇到这些问题时会采取的一些步骤:

  • error C2653: 'User' : is not a class or namespace name是关于您的用户定义类型之一。检查发生此错误的行,看看您是否可以发现问题(顺便说一下,如果您告诉我们错误发生在哪一行而不是给我们 4 个文件并说它在某处,这可能真的很有帮助!)。如果没有,那么...
  • ...您可能正面临一些#include/namespace 噩梦。
  • 摆脱using namespace std;. 作为临时解决方案,您可以通过 etc 导入您需要的内容using std::string; ,但对于可持续的长期方法,请阅读 Herb Sutter 的文章:http ://www.gotw.ca/gotw/053.htm
  • 从文件中删除所有不必要#include的 s。只包含您实际需要的内容!
  • 你的组合#pragma once和手动包括警卫对我来说似乎很奇怪。我认为这不会引起问题,但我会坚持两者之一。
  • stadfx.h从您的包含中删除禁用项目选项中的预编译头文件。重建你的项目。(我并不是说预编译的标头不好,但我会在您解决问题之前将它们删除。)
于 2013-03-10T13:10:41.993 回答