嗨,我試圖讀取數據到一個對象的矢量,但我有麻煩這樣做。我創建了該類的類和向量。當我嘗試讀取數據到矢量中時,我得到班級Bank Statements沒有成員,然後是我嘗試讀入的變量。將輸入讀入矢量對象
#include <iostream>
#include<vector>
#include <string>
using namespace std;
class Bank_Statement
{
public:
Bank_Statement();
Bank_Statement(int d, double bal, string desc);
private:
string description;
double balance;
int day;
};
Bank_Statement::Bank_Statement(int d, double bal, string desc)
{
description = desc;
balance = bal;
day = d
}
int main(){
Bank_Statement statement1;
cin >> statement1.d >> statement1.bal >> statement1.desc;
vector<Bank_Statement> user_statements;
int day_of_month;
for (day_of_month = 0, day_of_month < user_statements.size(); day_of_month++){
user_statements.push_back(statement1);
}
return 0;
}
你有部分權利,但它仍然無法正常工作,因爲它們是私密的。 – chris
這是正確的,但我認爲創建構造函數並使用cin >> statement1.d >> statement1.bal >> statement1.desc;將允許我輸入數據,但現在它說bank_statement沒有memeber。我覺得我很困惑。 – user2420948