VS6.0 (VC98) 標準庫支持有限,需確保包含 `
#include <vector>
#include <string>
#include <iostream>
using namespace std;
class Account {
public:
Account(int id, const string& name, double balance)
: id_(id), name_(name), balance_(balance) {}
void display() const {
cout << "ID: " << id_ << ", Name: " << name_ << ", Balance: " << balance_ << endl;
}
private:
int id_;
string name_;
double balance_;
};
int main() {
// 存放對象(值語義,會拷貝)
vector accounts;
accounts.emplace_back(1, "Alice", 1000.0);
accounts.emplace_back(2, "Bob", 2000.0);
// 遍歷
for (const auto& acc : accounts) {
acc.display();
}
// 若需存放指針(多態、避免拷貝),用 vector
// 需手動管理內存或配合智能指針(VS6 需自行實現或用 boost)
return 0;
}
VS6.0 std::vector 存放自定義對象,值語義與指針語義選擇,ATM 賬戶管理完整示例,兼容性注意事項。