include<iostream>
#include<string>
#include<vector>
#include<fstream>
using namespace std;
class plane
{
friend class information;
public:
float price; //普通座位的價錢,前兩排頭等座,價錢是普通定的1.5倍
string route[2];
char seatP62[12];
char seatP124[48];
plane(){}
void planeP62(string Route1, string Route2, float Price)
{
route[0] = Route1; //starting station
route[1] = Route2; //termianl station
price = Price;
for (int i = 0; i < 12; i++)
{
seatP62[i] = 'Y';
}
}
};
void storeP62(vector<plane>* P62)
{
ofstream fout("planeP62.txt");
fout << P62->size(); //the number of plane P62
for (int i = 0; i < P62->size(); i++)
{
fout << (*P62)[i].price << "\t\t\t" << (*P62)[i].route[0] << "\t\t\t" << (*P62)[i].route[1] << endl;
for (int j = 0; j < 12; j++)
{
fout << (*P62)[i].seatP62[j] << "\t\t\t";
}
fout << endl;
}
fout.close();
}
void readP62(vector<plane>* PlaneP62)
{
int num; //the number of plane P62
ifstream fin("planeP62.txt", ios::in);
fin >> num; //the number of P62
plane PLANE;
for (int i = 0; i < num; i++)
{
fin >> PLANE.price >> PLANE.route[0] >> PLANE.route[1];
for (int j = 0; j < 12; j++)
{
fin >> PLANE.seatP62[j];
}
PlaneP62->push_back(PLANE);
}
fin.close();
}
void add()
{
vector<plane>* Plane = NULL;
readP62(Plane);
int planetype;
string route[2];
float price;
cout << "1 P62 2 P124" << endl;
cin >> planetype;
cout << "starting place: ";
cin >> route[0];
cout << "termianl station: ";
cin >> route[1];
cout << "price: ";
cin >> price;
plane PLANE;
PLANE.planeP62(route[0], route[1], price);
Plane->push_back(PLANE);
storeP62(Plane);
}
void main()
{
add();
}
運行到紅色字體處就會程式有問題,難道指標不可以push_back一個類么?指標定義的就是那個類的形式啊
uj5u.com熱心網友回復:
起碼得先new一個 vector<plane>物件吧vector<plane>* Plane = new vector<plane>();
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/78765.html
標籤:基礎類
上一篇:C++連接資料庫 并輸入資料
