Could you help me organize a dynamic array of points?
I have coped with a dynamic array of integers. But I don't know how to organize it with structures.
Here is my code so far...
#include "stdafx.h"
#include <cstdlib>;
#include <iostream>;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int i = 0; // Array index.
struct Point
{
int x;
int y;
};
size_t n = sizeof(int);
int * points = static_cast<int*>(malloc(n));
char command;
do
{
cout << "n - Create new point." << endl;
cout << "q - Quit." << endl;
cout << "Input a new command: ";
cin >> command;
if (command == 'n')
{
points[i] = 1;
i++;
/* points[i] = new Point();
points[i].x = 1;
points[i].y = 1; */
// cout<<"("<<point1.x<<","<<point1.y<<")";
}
else if (command == 'q')
{
for (int j = 0; j < i; j++)
cout << points[j] <<endl;
system("pause");
return 0;
}
else
{
cout << "Please, enter a correct command." << endl << endl << endl;
}
} while (true);
system("pause");
return 0;
}