| Console Based Hello World! with Strings |
- Text files: pp1_16.cpp
- Code Setup and Compilation
//***************************************************************************************************************
// Program Phase 1-16 C++ wxWidgets Hello World! with Strings
// Programming Tasks Illustrated: Console Application
// Integer and String Variable Declarations
// Application Command Line Parameters
// Case/Switch Statement
// String Literal Assignment and Concatenation
// Console Application Standard Output
//***************************************************************************************************************
//***************************************************************************************************************
// File: pp1_16.cpp
// Reserved
//***************************************************************************************************************
#include <stdio.h>
#include "wx/wx.h"
//***************************************************************************************************************
// Program Phase 1-16 Main
// Define the Entry Point of Execution (EPE) for Program Phase 1-16
// CBI: 1-16.1.1.1
//***************************************************************************************************************
int main(int argc, char* argv[])
{
if (wxInitialize() == false)
{
wxFprintf(stderr,wxT("Failed to initialize wxWidgets.\n"));
return 1;
}
//***************************************************************************************************************
// Program Phase 1-16 Main
// Declare the local variables for the "main" program
// CBI: 1-16.1.1.2
//***************************************************************************************************************
int lnCmdLineParamCount;
wxString lcString1;
wxString lcString2;
wxString lcStringOutput1;
wxString lcStringOutput2;
//***************************************************************************************************************
// Program Phase 1-16 Main
// Store the command line parameters
// CBI: 1-16.1.1.3
//***************************************************************************************************************
lnCmdLineParamCount = argc - 1;
//***************************************************************************************************************
// Program Phase 1-16 Main
// Parse the command line parameters using a Case/Switch statement
// CBI: 1-16.1.1.4
//***************************************************************************************************************
switch(lnCmdLineParamCount)
{
case 0:
lcStringOutput1.Printf(wxT("You entered no command line parameters."));
break;
case 1:
lcStringOutput1.Printf(wxT("Command line parameter entered: %s"),
wxT(argv[1]));
break;
default:
lcStringOutput1.Printf(wxT("The command line is limted to 1 parameter."));
}
//***************************************************************************************************************
// Program Phase 1-16 Main
// Concatenate two string variables
// CBI: 1-16.1.1.5
//***************************************************************************************************************
lcString1.Printf(wxT("Hello"));
lcString2.Printf(wxT("World!"));
lcStringOutput2 << lcString1 << wxT(" ") << lcString2;
//***************************************************************************************************************
// Program Phase 1-16 Main
// Output to standard output
// CBI: 1-16.1.1.6
//***************************************************************************************************************
wxFprintf(stdout,wxT("%s\n"),lcStringOutput1.c_str());
wxFprintf(stdout,wxT("%s\n"),lcStringOutput2.c_str());
wxUninitialize();
return 0;
}