错误 C2653:'User':不是类或命名空间名称

error C2653: 'User' : is not a class or namespace name

本文关键字:命名空间 User C2653 错误      更新时间:2023-10-16

我知道网上已经有很多关于这个问题的帖子了。然而,这些答案对我没有帮助:(有人能帮助我吗?)我有相当多的类,但这些错误并不适用于所有的。这些错误是"随机"出现的,我不知道从哪里开始看。

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

  1. 包括预编译的头文件stdafx.h
  2. #include pragma once
  3. ifndefdefine均有影响

此外,我还得到奇怪的错误,如:

Error   507 error C2275: '_iobuf' : illegal use of this type as an expression 

以及许多其他语法错误。

我有10个。h和。cpp文件,所以我只复制粘贴2对有上面提到的错误。有人能帮我一下吗?谢谢你!

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

面对这些问题,我将采取以下步骤:

  • error C2653: 'User' : is not a class or namespace name是关于您的用户定义类型之一。检查发生错误的行,看看是否可以发现问题(顺便说一下,如果您告诉我们错误发生在哪一行,而不是给我们4个文件并说它在那里的某个地方,那么可能真的很有帮助)。如果没有,则…
  • …你可能面临一些#include/命名空间噩梦。
  • 去掉using namespace std;。作为临时解决方案,您可以通过using std::string;等导入所需的内容,但要获得可持续的长期方法,请阅读Herb Sutter的文章:http://www.gotw.ca/gotw/053.htm
  • 从文件中删除所有不必要的#include。只写你真正需要的东西!
  • 你的#pragma once和手动包含守卫的组合在我看来很奇怪。我认为这不会造成问题,但我会坚持使用两者中的一个。
  • 删除stadfx.h从您的包括禁用预编译头在您的项目选项。重新构建项目。(我不是说预编译头是坏的,但我会把它们拿出来,直到你已经解决了你的问题。)