12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
// prata 9-3 bufer new.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "iostream" #include <string> #include <conio.h> #include <new> struct chaff { char dross[20]; int slag; }; char buffer[512]; void show_chaff(chaff *, short); int _tmain(int argc, _TCHAR* argv[]) { const short s_ar_size=2; using std::cout; using std::cin; using std::endl; chaff *chaff_ar=new (buffer) chaff[s_ar_size]; show_chaff(chaff_ar,s_ar_size); for (int i=0; i<s_ar_size; i++) { cout<<"Enter dross\n"; cin.getline(chaff_ar[s_ar_size].dross,19); cout<<"Enter slag\n"; while (!(cin>>chaff_ar[s_ar_size].slag)) { cin.clear(); cin.ignore(64,'\n'); cout<<"Enter rigt value!\n"; } cin.get();//number input - take '\n' } //show_chaff(chaff_ar,s_ar_size); for (int i=0; i<s_ar_size; i++) std::cout<<chaff_ar[i].dross<<"\t"<<chaff_ar[i].slag<<"\n"; getch(); return 0; } void show_chaff(chaff *ch_ar, short s) { for (int i=0; i<s; i++) std::cout<<ch_ar[i].dross<<"\t"<<ch_ar[i].slag<<"\n"; }