Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / How to get cout to work with Dark GDK

Author
Message
Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 16th Jun 2011 19:17 Edited at: 16th Jun 2011 19:17
well to start off i can get cout to work when im not using dark gdk just c++ but when i try to use dark gdk with it it say this error
i do have iostream as a header file also as well as dak gdk. i want it so you can still type and and i was just testing this so the code is very small did i put it in the wrong spot?
if someone could tell me why this is not working for me that would be great thankyou
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 16th Jun 2011 19:38
you don't really want to use cout, anyway

Mistrel
Retired Moderator
19
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 16th Jun 2011 19:43
cout is part of the std namespace. So you either need to use "std::cout" or first include using "namespace std;" to bring std:: into scope.

Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 16th Jun 2011 20:58
It won't work just like that. cout writes to a console (text) output but Dark GDK is a graphical program, so the output has nowhere to go.

There was a thread earlier about how to open a separate console window together with your Dark GDK program and redirect the output to there. I tested it, it works. Here is the thread if you wish to use this solution:

http://forum.thegamecreators.com/?m=forum_view&t=169941&b=22
Red Eye
16
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 16th Jun 2011 21:03
Ofcourse you can use _cout.



...haha.

Mistrel
Retired Moderator
19
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 16th Jun 2011 22:02
Quote: "It won't work just like that. cout writes to a console (text) output but Dark GDK is a graphical program, so the output has nowhere to go."


I don't use Visual Studio but doesn't stdout just redirect to the output view?

Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 16th Jun 2011 22:15
No, nothing appears in the output window if you print something to cout while a Dark GDK program is running. Besides, this console solution by Bran flakes91093 that I quoted above works even if you start the program outside Visual Studio.
Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 17th Jun 2011 20:51 Edited at: 17th Jun 2011 22:49
Since i dont under stand the thing that looks like a win32app thing im not going to use it but is there somthing in dark gdk that the user could type and it would come up on dark gdk instead of command promt thing?
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 18th Jun 2011 14:38 Edited at: 18th Jun 2011 14:40
Only two days ago did I recommend my input function to another forum member, I think it will be useful for you too. You can call this function every loop until you detect a return key. It will store user input in a char array, which you can display on any part of the screen with dbText. The function also handles backspace.

http://forum.thegamecreators.com/?m=forum_view&t=160546&b=22&msg=1898323#m1898323
Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 19th Jun 2011 03:00
when calling the function it says
i will give you the code i tryed it on

did i put it in right spot?
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 19th Jun 2011 11:15 Edited at: 19th Jun 2011 11:19
A function should be declared before you call it. One solution is to put the whole GetInput function before the "void DarkGDK(void)" function, but there is an easier way: make a forward declaration. This means writing just the function header at the beginning of the program, and then the function body can remain where it is now. This is useful, since in a big program it's not always possible to place functions in the order in which they are going to be called.

There are also a few other problems in the main loop. If you want to see what you type on the screen, then you should display the contents of the "Entry" array with dbText. Put the declaration of "Entry" before the game loop, because if it gets erased and re-created every loop, then the contents will be erased and you will only get the last character typed, not the whole string. Finally, I would clear the screen as well every loop, because this program does not have a background, and if you delete back the string, the previous characters will not get deleted without clearing the screen.

Here is the program with the suggested modifications.

Michael P
18
Years of Service
User Offline
Joined: 6th Mar 2006
Location: London (UK)
Posted: 19th Jun 2011 16:58
You should be able to set the output device that cout uses somehow. cout is very useful, and is vastly superior to the output functions provided with DarkGDK which are pretty awful.

Login to post a reply

Server time is: 2024-11-19 09:43:05
Your offset time is: 2024-11-19 09:43:05