首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

哪位帮小弟我改改啊到底哪错了

2012-03-27 
哪位大虾帮我改改啊..到底哪错了啊#include stdafx.h#include iostream.h#include stringusing name

哪位大虾帮我改改啊..到底哪错了啊
#include "stdafx.h"
#include "iostream.h"
#include "string"
using namespace std;

struct car
{
string maker;
string years;
} cars;

int main(int argc, char* argv[])
{
int i,sum;
cout << "How many cars do you wish to cataog?\t";
cin >> sum;
cars *pc = new cars[sum];
for(i=0;i<sum;i++)
{
cout << "Car #" << i <<":\n"
<< "Please enter the make:";
cin >> pc[i]->maker;
cout << "Please enter the year made:";
cin >> pc[i]->years;
}
cout << "Here is your collection:\n";
for(i=0;i<sum;i++)
{
cout << pc[i]->years <<'/t'<<pc[i]->maker<<endl;
}
delete p;
return 0;
}


[解决办法]
pc[i]- >make; -> pc[i].maker; //其它同

delete p; -> delete []pc;
[解决办法]

C/C++ code
#include <iostream>#include <string> using namespace std; typedef struct car {     string maker;     string years; }cars; int main(int argc, char* argv[]) {     int i,sum;     cout  << "How many cars do you wish to cataog?\t";     cin   >> sum;     cars *pc = new cars[sum];     for(i=0;i <sum;i++)     {         cout  << "Car #"  << i  <<":\n"             << "Please enter the make:";         cin   >> pc[i].maker;         cout  << "Please enter the year made:";         cin   >> pc[i].years;     }     cout  << "Here is your collection:\n";     for(i=0;i <sum;i++)     {            cout  << pc[i].years  << '/t ' <<pc[i].maker <<endl;     }     delete pc;     return 0; } 

热点排行