Mar 13, 2015 at 6:41am UTC
I am taking a 2d charinfo vector and trying to convert it to a dynamic 2d CHAR_INFO array to pass to a function. I am not sure how i would copy this, and the other problem, is i have this code for my copy. The code may be for windows, but the concept is standard.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include <vector>
#include <windows.h>
int main()
{ //Imagine you had stuff in mainvector
int width=10;
int height=10;
std::vector <std::vector < CHAR_INFO > > mainvector;
//Resize loop
mainvector.resize(height); //Yes, this is correct, in char_info arrays
for (int i; i<width; i++) //It needs to be height, width, to the function
mainvector[i].resize(width);
CHAR_INFO * array = new CHAR_INFO[height][width];
for (int countery; countery<height; countery++)
for (int counterx; counterx<width; counterx++)
array[countery][counterx]=mainvector[countery][counterx];
COORD dwBufferSize = { width, height }; //This doesn't quite matter
COORD dwBufferCoord = { 0, 0 };
SMALL_RECT rcRegion = { 0, 0, width, height };
HANDLE hOutput = (HANDLE)GetStdHandle( STD_OUTPUT_HANDLE );
WriteConsoleOutput( hOutput, (CHAR_INFO *)array, dwBufferSize,
dwBufferCoord, &rcRegion );
}
However, my MinGW Codeblocks setup is saying that width and height need to be constants.
error: array size in operator new must be constant
Please Help
Last edited on Mar 13, 2015 at 6:54am UTC
Mar 13, 2015 at 6:44am UTC
std::vector <std::vector < CHAR_INFO > > mainvector;
ยด
How can you create a vector of CHAR_INFO before telling the program what CHAR_INFO is, or am I missunderstanding something?
Mar 13, 2015 at 6:47am UTC
Char info is a struct defined by windows.
Mar 13, 2015 at 6:51am UTC
&TarikNeaj CHAR_INFO is part of the windows.h header file. However, the op does need to include vector.
Last edited on Mar 13, 2015 at 6:51am UTC
Mar 13, 2015 at 6:54am UTC
Sorry, i hadnt posted all the code, i just wrote an example of what i was trying to do, but i am getting the error
error: array size in operator new must be constant
Mar 13, 2015 at 7:08am UTC
Thank you, that worked perfectly
Mar 13, 2015 at 7:13am UTC
Just to warn that naraku9333 example should not be used with WriteConsoleOutput and similar functions.
Mar 13, 2015 at 7:32am UTC
OK then, what way could I make it to pass to a function like that?
Mar 13, 2015 at 7:42am UTC
Probably something like CHAR_INFO* ci = new CHAR_INFO[w * h]; See article MiiNiPaa linked to.