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

Programming, for all ages and all languages.
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

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

Post 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?
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

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

Post 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.
My OS is Perception.
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post 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?
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post 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.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post 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
Every good solution is obvious once you've found it.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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.
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Post 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.
My OS is Perception.
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post 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.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post 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..)
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post 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:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post 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.
Every good solution is obvious once you've found it.
User avatar
eboyd
Member
Member
Posts: 97
Joined: Thu Jul 26, 2007 9:18 am
Location: United States

Post 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;
}
User avatar
eboyd
Member
Member
Posts: 97
Joined: Thu Jul 26, 2007 9:18 am
Location: United States

Post by eboyd »

bah!!! stupid code thing!
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Try this thread (scroll down to Radagar's post).
Post Reply