您的位置:首页 > 其它

new 创建动态结构小例子

2016-07-13 09:50 387 查看
#include <iostream>
#include <string>

const int Size = 20;
char name[Size];
struct sss
{
char name[Size];
double A;
double B;
};

int main()
{
using namespace std;

sss *s = new sss;

cout << "Please to Enter the A:";
cin >> s->A;

cin.get();  // 这个是重点,没有此行就无法读取下边一行代码,
cout << "Enter the name:";
cin.getline(s->name,20);
cout << "Enter the B:";
cin >> s->B;

cout << "Weight: " << s->A << endl;
cout << "Name: " << s->name << endl;
cout << "Caloar: " << s->B << endl;

delete s;

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: