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.

AppGameKit Classic Chat / AGK with Visual Studio = Console Window??? (std::cout)

Author
Message
Daqs
8
Years of Service
User Offline
Joined: 23rd May 2015
Location:
Posted: 28th May 2015 11:17
I am using Tier 2 AppGameKit with C++. std::cout does not display anything since there is no console window? Does anyone know how to use std::cout in Visual Studio with AppGameKit?

When I run the program with std::cout statement in agk::begin or agk::loop, nothing shows up on the screen. I only see a bunch of debug commands on the output window of VS 2013.

Thanks!
Lucas Tiridath
AGK Developer
15
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 28th May 2015 22:10
Hi Daqs. You're right; on Windows, AppGameKit creates a native windows program, which doesn't have an input or output stream set by default as a console program does.

You have a couple of options here, depending on what you want. Both of these are Windows specific. If all you want is a way to print out debugging messages, I reccommend using the OutputDebugString function, which will write arbitrary text to the Visual Studio console.


However if you want to have an actual output stream and use std::cout, then you will need to create and connect a new console. Do do this, simply place these lines at the top of your program (e.g. in app::Begin).

With that done, std::cout will work as expected. Note that in this case though, when you launch your program, you will have a second console window open.

I hope that helps.

Daqs
8
Years of Service
User Offline
Joined: 23rd May 2015
Location:
Posted: 29th May 2015 16:23
Thank you!
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 8th Jun 2015 03:48 Edited at: 8th Jun 2015 04:00
This code works on all platforms. I have not tested it in V2 for iOS or Android, yet. But I just tested it in Windows 7 Pro, MS VS 2013 and AppGameKit V2.014.

Header (ta_debug_console.h):


Implementation (ta_debug_console.cpp):


Here are the template.h/.cpp files for my demo project (which does involve a lot of other files, but it shows the basic usage for the class above):




On a Windows box, this will open a separate window that strings can be written to. For iOS/Mac, the messages will be displayed in the Xcode message area. For Android, it assumes connection to Eclipse and outputs to its message window.

The code is part of a project that demonstrates state machines, http connections, multi-platform coding and a few other things. Eventually, I will get the whole project finished with associated tutorial explaining it all.

Here are the handle_object.h/.cpp files (where the 'makeStateChange' method lives):



Cheers,
Ancient Lady

Login to post a reply

Server time is: 2024-04-24 14:35:11
Your offset time is: 2024-04-24 14:35:11