14.3. Simple Examples

To get a feel for the console's capabilities, let's start with two simple examples. The first one, shown in Listing 14.1, demonstrates the simplest possible use of a console in cooked mode. When you run the program, it will echo input line by line until you type the word "exit."

Code Listing 14.1. A simple console program
 // cooked.cpp #include <windows.h> #include <iostream.h> #include <string.h> void ErrorHandler(char *s, DWORD err) { cout << s < endl; cout << "Error number: " << err << endl; ExitProcess(err); } void ProcessIO(HANDLE consoleStdin, HANDLE consoleStdout) { char buffer[1000]; DWORD numRead, numWrite; do { ReadFile(consoleStdin, buffer, 1000, &numRead, 0); buffer[numRead]='\0'; // will have CR/LF WriteFile(consoleStdout, ...

Get Win32 System Services: The Heart of Windows® 98 and Windows® 2000 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.