Go Back  Xtreme Visual Basic Talk > Other Languages > Miscellaneous Languages > cout and cin functions


Reply
 
Thread Tools Display Modes
  #1  
Old 03-17-2004, 05:39 PM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,718
Default cout and cin functions


Can the cout and cin functions be used in a win32 app?
Reply With Quote
  #2  
Old 03-17-2004, 06:39 PM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,724
Default

Yes, but only if that's a win32 console app.
Reply With Quote
  #3  
Old 03-17-2004, 08:07 PM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,718
Default

That explains why I coudn't get them to work!

Is there something similar for a Windows app?

I wan't to be able to see a steady stream of output (windows messages) appear
in the window, and then be able to scroll the window back and forth to review
the output.

BTW, I did see some cout & cin statements in some code posted on the net.
Reply With Quote
  #4  
Old 03-17-2004, 08:18 PM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,724
Default

How about up and down? listbox maybe?
Reply With Quote
  #5  
Old 03-17-2004, 08:23 PM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,718
Default

OK, I can try...
Reply With Quote
  #6  
Old 03-17-2004, 10:30 PM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,718
Default

Couldn't get the listbox working yet, but I will try again later, as I like the idea.

In the meantime, I got something else working (sort of).

I wrote the following function which gets called everytime a message is sent and will append to a file that message.

static
void FileWrite()
{
fprintf( stream, "%d\n", msg );
}

It seems to work; a file is created and it is filled with hundreds of numbers.

Now I have to figure out what these numbers mean.

How could I find the message associated with these values?
Reply With Quote
  #7  
Old 03-17-2004, 10:54 PM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,724
Default

WinUser.h will have many of them.
Reply With Quote
  #8  
Old 03-17-2004, 10:56 PM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,718
Default

OK, thanks!
Reply With Quote
  #9  
Old 03-18-2004, 01:24 AM
Squirm's Avatar
Squirm Squirm is offline
Political Coder

Retired Moderator
* Guru *
 
Join Date: Mar 2001
Location: London, England
Posts: 8,037
Default

Note that if you want to use a console in a conventional Win32 application, for debugging purposes for example, you can use AllocConsole, GetStdHandle, WriteConsole, CloseHandle and FreeConsole:

Code:
//At app start or when you want to debug
AllocConsole();
hCon = GetStdHandle(STD_OUTPUT_HANDLE);

//Elsewhere, when it comes to writing to the console (handle wrapper function)
VOID PrintConsole(LPTSTR lpzFormat, ...)
{
	static TCHAR	zBuff[1024];
	static va_list	vaList;
	
	if (_tcslen(lpzFormat) > 1023) {
		WriteConsole(hCon, lpzFormat, (DWORD) _tcslen(lpzFormat), NULL, NULL);
	} else {
		va_start(vaList, lpzFormat);
		_vstprintf(zBuff, lpzFormat, vaList);
		va_end(vaList);
		WriteConsole(hCon, zBuff, (DWORD) _tcslen(zBuff), NULL, NULL);
	}
}

//And to call:
PutConsole("Message = %u\n", msg.wParam);

//When you've finished with the console:
CloseHandle(hCon);
FreeConsole()
__________________
Search the forums | Use [vb][/vb] tags | Still IRCing
Reply With Quote
  #10  
Old 03-18-2004, 05:55 AM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,718
Default

That's excellent, Thank You! (I've always wanted something like that exactly
for the purpose of debugging)

Where can I find more info on those special characters (ie %u\n)?

Also, I found that adding the line (to my text file output method):

system(print "fprint.txt")

caused a "console" to appear and disappear very quickly (too quickly to read
anything).

Is there something I could add to that line to make it "pause" until I am
finished reading it?
Reply With Quote
  #11  
Old 03-18-2004, 07:56 AM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,724
Default

system("pause");

Reply With Quote
  #12  
Old 03-18-2004, 10:12 AM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,718
Default



(I did check for system in the help files; it was not there)
Reply With Quote
  #13  
Old 03-18-2004, 11:16 AM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,724
Default

Reply With Quote
  #14  
Old 03-18-2004, 01:25 PM
Squirm's Avatar
Squirm Squirm is offline
Political Coder

Retired Moderator
* Guru *
 
Join Date: Mar 2001
Location: London, England
Posts: 8,037
Default

Quote:
Is there something I could add to that line to make it "pause" until I am
finished reading it?
I usually suspend the current thread as the very last statement in the application, then I just close the console box when I'm finished looking at the output:

Code:
SuspendThread(GetCurrentThread());
This does mean that you haven't closed the console handle or freed the thread within the application, but I hope that Windows is smart enough to do that little bit of housework for us. Of course, this is only for debugging.

__________________
Search the forums | Use [vb][/vb] tags | Still IRCing
Reply With Quote
  #15  
Old 03-18-2004, 02:30 PM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,724
Default

system("pause"); is a very simple way to pause. But of course it's not portable. Then again, neither is win32 console code.

This IS a portable way to pause a console:

Code:
void wait(void)
{
    std::cout << "\nPress Enter to continue.\n";
    std::cin.ignore(INT_MAX, '\n');
}
Reply With Quote
  #16  
Old 03-18-2004, 08:57 PM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,718
Default

Thanks guys!

OnErrOr:

Checked out the link you referenced: ...wsystem.asp

I must be blind, I can't find any comands system accepts (not even pause).

What do you mean by system("pause") not portable?
Reply With Quote
  #17  
Old 03-18-2004, 10:30 PM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,724
Default

system() passes commands to the command interpreter. Which means you should be able to pass anything you can use in a DOS/Command/Cmd window. Try system("dir"); for kicks before system("pause");

Portable means that the code will work on various operating systems. C++, if written correctly, can work on more than just Windows.
Reply With Quote
  #18  
Old 03-18-2004, 10:34 PM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,718
Default

I understand (now), Thanks!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->