用vector存储信息,编译时异常
#include<iostream>
#include<vector>
using namespace std;
class xinxi
{
public:
void xingxi(const char* l,int a, double b,const char* c)
{
vector<const char*>a4;
a4.push_back(l);
vector<int>a1;
a1.push_back(a);
vector<double>a2;
a2.push_back(b);
vector<const char*>a3;
a3.push_back(c);
cout << "库存的水果信息如下:" << endl;
cout << a4.at(1) << " " << endl;
cout << a1.at(1) <<"kg"<< " " << endl;
cout << a2.at(1) << "元"<<" " << endl;
cout << a3.at(1) << " " << endl;
cout << a4.at(2) << " " << endl;
cout << a1.at(2) <<"kg"<< " " << endl;
cout << a2.at(2) << "元"<< " " << endl;
cout << a3.at(2) << " " << endl;
cout << a4.at(3) << " " << endl;
cout << a1.at(3) <<"kg"<< " " << endl;
cout << a2.at(3) << "元"<< " " << endl;
cout << a3.at(3) << " " << endl;
}
};
int main()
{
xinxi q;
q.xingxi("红美人", 100, 15.3, "象山");
q.xingxi("车厘子", 78, 48.8, "智利");
q.xingxi("香梨", 132, 7.8, "新疆");
return 0;
}
错误信息:错误信息:0x00007FFE5A5ACD29 处(位于 储存库存信息.exe 中)有未经处理的异常: Microsoft C++ 异常: std::out_of_range,位于内存位置 0x00000010D9DBF410 处。