Page 1 of 2

One of those really stupid questions... (C++)

Posted: Mon Aug 20, 2007 11:46 pm
by Zacariaz
I need to print a char at a specific position in the console windows, obiously it is possible, but eludes me.

i would like a function like:

draw(x, y, char);

anyone?

Re: One of those really stupid questions... (C++)

Posted: Tue Aug 21, 2007 12:34 am
by AndrewAPrice
Zacariaz wrote:I need to print a char at a specific position in the console windows, obiously it is possible, but eludes me.

i would like a function like:

draw(x, y, char);

anyone?
Use the console code from Brendon's kernel tutorial from osdevver.net.

Posted: Tue Aug 21, 2007 12:42 am
by Zacariaz
i seem to remember being told about that tutorial before, only problem being that i never was able to find it. a link maybe?

Posted: Tue Aug 21, 2007 12:48 am
by Zacariaz
ok, maybe i did find the tutorial after all, but i really dont care to read like a billion line of code that i dont understand just to get this little snippet.
Thank you for your help, but this is definently not usefull. If you can point me to were i should look, then maybe, but otherwise.

And just to make clear, this has nothing to do with osdeving.

as a little non important side thing i allso need to disable the cursor, thingy, stop the screen from scroling and stuff, maybe there is a tutorial somewhere that has to do with all these thing? I havent been able to find one my self.

Posted: Tue Aug 21, 2007 1:45 am
by Solar
C++, as far as the language itself is concerned, does not have such a function. It is a system language, like C, and just like C its standard library covers only the essentials of data handling, and little else - which is left to third-party libraries.

I know this is confusing for people coming from Java or .NET, where there is a "standard library" that is good for everything and your kitchen sink, but those are a different breed of languages. (And while my Java is a mite rusty, I'd daresay you don't have console-positioning in Java, either.)

But of course there are libraries available for the C++ programmer that do what you intend to do. For Unix-alike systems, the "default" choice is ncurses. Don't ask me about pointers to Windows console programming resources, that's sick. :-D

Posted: Tue Aug 21, 2007 2:25 am
by pcmattman
What OS are you using? I know how to do console modifications in Windows and can point you to some links if you need them.

Posted: Tue Aug 21, 2007 6:34 am
by AndrewAPrice
Does he mean std::cout? I know there are Windows specific functions (like changing colour, setting position, setting the title) in the Windows SDK.

Posted: Tue Aug 21, 2007 11:23 am
by Zacariaz
I am using windows yes.
about std::cout im sure yiou can modify color and stuff, but as for possition... ? i doubt it.

Posted: Tue Aug 21, 2007 12:08 pm
by Brynet-Inc
For such "interactive" console applications, I use BSD curses or ncurses..

I heard that Windows users (Among others..) can use pdcurses, but I don't think it supports everything though..

The sourceforge projects summary states: "An implementation of the curses library for Win32, DOS, OS/2, X11 and SDL."

So have fun 8)... (The ability to port old curses applications to SDL/X11 sounds appealing..)

Posted: Tue Aug 21, 2007 12:15 pm
by Zacariaz
i supose you have allready figured out why im asking these questions?
ASCII GAMES OF COURSE!
I've never actually done any, so i thought i would.

Posted: Tue Aug 21, 2007 2:48 pm
by Combuster
Zacariaz wrote:i supose you have allready figured out why im asking these questions?
ASCII GAMES OF COURSE!
Have you tried good ole' ZZT? :twisted:

Posted: Tue Aug 21, 2007 2:52 pm
by Solar
Zacariaz wrote:I am using windows yes.
about std::cout im sure yiou can modify color and stuff...
Nope.

Well, maybe you can squeeze ANSI sequences through cout which happen to be interpreted as color codes by the console driver, but that's not the droid you're looking for.
, but as for possition... ? i doubt it.
That's what I said: C++ doesn't offer this in the standard language proper, you need third-party libraries for that. Use one of the pointers given already, or google for "console library Windows" or somesuch to find out what's available that suits your needs.

Posted: Tue Aug 21, 2007 3:09 pm
by eboyd

Code: Select all

#include <windows.h>

int main(){
    
    HANDLE console_handle;
    COORD cursor_coord;
    char *buffer = "X\n";
    DWORD actual = 0;

    cursor_coord.X=(40-(strlen(buffer)/2));
    cursor_coord.Y=10;

    console_handle = GetStdHandle(STD_OUTPUT_HANDLE);

    if(SetConsoleCursorPosition(console_handle, cursor_coord)){
    
        WriteConsole(console_handle, buffer, strlen(buffer), &actual, NULL);
    }
    
    
    system("pause");
    return 0;
}

Posted: Tue Aug 21, 2007 3:10 pm
by eboyd
bah!!! stupid code thing!

Posted: Tue Aug 21, 2007 3:59 pm
by pcmattman
Try this thread (scroll down to Radagar's post).