你能帮我组织一个动态的点数组吗?
我已经处理了一个动态的整数数组。但我不知道如何用结构来组织它。
到目前为止,这是我的代码...
#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;
}