How do I write some expression to the console screen from an MFC application?

I have an application mfc

that I launch via the command line. Where I will enter some specified syntax. If I gave incorrect syntax, at the moment I am showing a message box. But instead of showing the message, I can write the same message to the same console, where am I trying to run my application?

Can someone kindly let me know how we can write to the console from an MFC application.

+3


source to share


3 answers


I think Console :: WriteLine () and AttachConsole () can do the trick

example:



#include "windows.h"
#pragma comment(lib, "kernel32.lib")

[STAThread]
int main()
{
    AttachConsole(-1);  //Use the console of the parent of the current process.

    Console::WriteLine("wrongsyntax");  //This will write to the command prompt

    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false); 
    Application::Run(gcnew Project::MyForm);
}

      

+1


source


This is useful:

How do I get the exit code of an application from the Windows command line?



Start /wait program.exe
Echo %errorlevel%

      

So, display a prompt, run the application, the application will set the error number in InitInstance and exit, then you will see the error number.

0


source


You can use cout

to display data on console like:

std::cout<< "Hello World"

      

-2


source







All Articles