2013-03-10 64 views
-2

我知道网上已经有几个帖子出现这个问题。然而,答案并没有帮助我:(有人能够帮助我吗?我有很多类,但这些错误并不适用于所有这些错误类型的“随机”出现,我不知道在哪里我该开始寻找,我都试过,但没有帮助错误C2653:'用户':不是类或名称空间名称

解决方案:

  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对他们有上面提到的错误。有谁能帮我解决这个问题吗?谢谢!

//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; 
} 
+3

*“我有10个.h和.cpp文件,所以我只复制粘贴2对他们有上面提到的错误。“*你一定可以放下发布的代码,因为即使这[太过](http://sscce.org)。还包括_exact错误消息_。顺便说一下,我想你忘了在一个点上包含你的标题。 – Zeta 2013-03-10 12:33:48

+0

这是相当数量的代码。当然,你不是一次写这个,然后第一次编译它?对最后一次已知的编译版本进行比较,并比较你所做的更改,如果错误消息对你没有帮助,这将帮助你找到可能的原因。 – us2012 2013-03-10 12:37:37

+0

你可能在包含中有一个循环 - 没有任何包含守卫的帮助。他们大多数是不必要的 - “User.h”只需要''(并且不应该*使用名称空间标准'说'),所有其他类都可以被转发声明。 – molbdnilo 2013-03-10 12:39:44

回答

4

这里有一些步骤面临这些问题的时候,我会采取:

  • 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禁用项目选项中的预编译头。重建你的项目。(我不是说预编译头文件不好,但我会把它们取出来,直到你解决了你的问题。)
相关问题