|

楼主 |
发表于 2017-10-30 16:31:18
|
显示全部楼层
改过了编译报错
||=== Build: Debug in 1 (compiler: GNU GCC Compiler) ===|
D:\mxf\src\tmp\1\main.cpp||In function 'int main()':|
D:\mxf\src\tmp\1\main.cpp|13|error: initializer fails to determine size of 'a'|
D:\mxf\src\tmp\1\main.cpp|13|error: array must be initialized with a brace-enclosed initializer|
D:\mxf\src\tmp\1\main.cpp|26|warning: deleting array 'a'|
||=== Build failed: 2 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|
- #include <iostream>
- struct car{
- char maker[15];
- int made_year;
- };
- int main(){
- using namespace std;
- cout<<" How many cars do you wish to catalog?";
- int quantity=0;
- cin>>quantity;
- cin.get();
- car * a[] = new car[quantity];
- for(int b=0;b<quantity;b++){
- cout<<"Car #"<<b+1<<":\n";
- cout<<" Please enter the make:";
- cin.get(a[b]->maker,14);
- cin.get();
- cout<<"Please enter the year made:";
- cin>>a[b]->made_year;
- cin.get();
- };
- cout<<"Here is your collection:\n";
- for(int b=0;b<=quantity;b++)cout<<a[b]->made_year<<" "<<a[b]->maker<<endl;
- cout<<"goodbye2"<<endl;
- delete [] a;
- return 0;
- }
复制代码 |
|