|
10鱼币
谢谢- // newstrct.cpp -- using new with a structure
- #include <iostream>
- struct inflatabe //structure template
- {
- char name[20];
- float volume;
- double price;
- };
- //typedef struct inflatable Inflatable;
- int main()
- {
- using namespace std;
- struct inflatable * ps;
- // *ps={"John",3.9,2};
- // struct inflatable* ps = new inflatable; // allot memory for structure
- cout << "Enter name of inflatabe item: ";
- cin.get(ps->name,20);
- cout << "Enter volume in cubic feet: ";
- cin >> (*ps).volume; // method 2 for member access
- cout << "Enter price: $";
- cin >> ps->price;
- cout << "Name: " << (*ps).name << endl; // method 2
- cout << "Volume: " << ps->volume << " cubic feet\n"; // method 1
- cout << "Price: $" << ps->price << endl; // method 1
- // delete ps;
- return 0;
- }
复制代码
gcc 6.4.0
基础不扎实呀
重新学一下C++吧
- // newstrct.cpp -- using new with a structure
- #include <iostream>
- struct inflatabe //structure template
- {
- char name[20];
- float volume;
- double price;
- };
- //typedef struct inflatable Inflatable;
- int main()
- {
- using namespace std;
- //struct inflatable * ps;
- struct inflatabe *ps = nullptr;
- // *ps={"John",3.9,2};
- // struct inflatable* ps = new inflatable; // allot memory for structure
- cout << "Enter name of inflatabe item: ";
- cin.get(ps->name, 20);
- cout << "Enter volume in cubic feet: ";
- cin >> (*ps).volume; // method 2 for member access
- cout << "Enter price: $";
- cin >> ps->price;
- cout << "Name: " << (*ps).name << endl; // method 2
- cout << "Volume: " << ps->volume << " cubic feet\n"; // method 1
- cout << "Price: $" << ps->price << endl; // method 1
- // delete ps;
- return 0;
- }
复制代码
|
|