How do I check what specific char has been outputted to a specific xy position in the console?

How do I check what specific char has been outputted to a specific xy position in the console?

I am working on a rouge-like demo game to test my knowledge and try learn new/better ways to do things in the console.

I have player movement set up, I'm just wanting to see how I can check what specific char has been outputted into the console at a certain xy coord.
You could keep track of your characters by mirroring the playground by a two-dimensional array.
keep track of it in a 2-d x/y mapping is the easiest way.
as you surely know by now, c++ console support is rather limited and additional libraries with whatever capability are needed to really make cool stuff. Are you suing something like ncurses etc?
@jonnin

I'm going to assume that ncurses is an external library, and the answer is no - I'm using straight C++17 on Windows 10

I can have a look at it and see where it leads me!


If you're using Windows, then you can use the Windows console functions to read/write from the console.

See https://docs.microsoft.com/en-us/windows/console/console-functions

Note ReadConsoleOutputCharacter()

You can also use VT100 codes. See https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences

@seeplus

I've searched the Microsoft Virtual Terminal Sequence (VT100) documentation and do not see a sequence to read back a character (or characters) from the screen.

ESC [6r
will read back the cursor position.
ESC [0c
Will read device attributes.
But that's the extent of anything I see that will read anything from the console window in VT100 mode.
I don't think you can.
You can still track a 2-d buffer that represents the screen and what is there, keeping it in sync. Then you can read that if you need to read.
Re VT100. OK. It's a while since I used these... In that case use the Windows console functions from which you can read from the output buffer (ReadConsoleOutputCharacter())
https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
A better way would be to not use your screen as a database.
The Windows console is based upon a resizeable 2-d buffer and a window display onto that buffer. If the buffer is larger than the window, then the shown window can be moved over the buffer to display the required part. The buffer can certainly be used as a '2-d array' to read/write from. You don't need a separate array to represent the console buffer.
Topic archived. No new replies allowed.