15,440
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <new>
struct chaff
{
char dross[20];
int slag;
};
int attact()
{
return sizeof(chaff);
}
const int Arsize = 3*attact();
int main()
{
using namespace std;
char place[Arsize];
chaff *first = new(place) chaff[2];
cout << (void *)place << endl;
for(int i = 0; i < 2; i++)
{
cout << first + i << endl;
cout << "Input the data:\n";
cout << "The string:";
cin.getline((first + i )->dross,20);
cout << "The num:";
(cin >> (first + i )->slag).get();
cout << "i = " << i << endl;
}
cout << "Quit success\n";
for(int i = 0; i < 2; i++)
{
cout << first + i * attact()<< endl;
cout << "Input the data:\n";
cout << "The string:";
//cin.getline((first + i * attact())->dross,20);
cout << (first + i * attact())->dross << endl;
cout << "The num:";
cout << (first + i * attact())->slag << endl;
}
return 0;
}