[英]building an array or matrix from stdin
I'm trying to build an array / matrix from a command given through stdin . 我正在尝试通过通过stdin给出的命令来构建数组 / 矩阵 。 The command is formatted like this:
该命令的格式如下:
nameOfArray build numberOfDimensions : dimensionList : valueList
Another example: 另一个例子:
B build 1 : 3 : 4,5,6
The command needs to work for up to three dimensions, and I am completely stumped as to how to implement it. 该命令最多需要在三个维度上起作用,而我对如何实现它一无所知。
Since we are limited to three dimensions, the problem is easy. 由于我们限于三个维度,因此问题很容易。 We simply treat all the cases as the 3 dimensional case, with height and depth set to one for the lower dimensions.
我们将所有情况简单地视为3维情况,将较低维度的高度和深度设置为1。
So we set up the array with malloc() or std::vector::resize() width * height * depth, then read the values in one by one. 因此,我们使用malloc()或std :: vector :: resize()width * height * depth设置数组,然后一一读取值。 In C, the job is done.
在C语言中,工作已完成。 In C++, you might then need to fiddle about to turn your vector into a multi-dimensional matrix class with a nice interface.
然后在C ++中,您可能需要花力气将向量转换为具有漂亮接口的多维矩阵类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.