Search code examples
c++buildervcl

Using console in VCL applications


Is there a way for using the console for output in VCL applications? Where does cout actually direct the stream in VCL applications?


Solution

  • I did it as follows:

    void TForm1::Button1Click(TObject *Sender)
    {
        out_to_console("Some text\n");
    }
    void out_to_console(std::string str)
    {
        AllocConsole() ;
        AttachConsole(GetCurrentProcessId()) ;
        std::freopen("CON", "w", stdout) ;
        std::cout<<str;
    }
    

    Two questions still remain for me open:

    1. Why I need the escape sequence \n to see the text Some text on the console?
    2. Where does stdoutpoint to in VCL applications?