Thread: beginners question: write onto command line

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    13

    beginners question: write onto command line

    i am writing a program withh c++ using winapi, mingw using option -mwindows to link

    when i run the program in my dev.environment (eclipse), 'cout' work.

    when i run the program .exe file in command prompt (old DOS prompt, found under startmenu/extras), 'cout' doesnt do anything.

    is there a way to get the program to write onto the command prompt and also receive input ('cin')

    thanks

    asta

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Give an example of some code?

    Code:
    #include <iostream>
    
    int main(int argc, char *argv[])
    {
    	std::cout << "Hello, world!" << std::endl;
    	return 0;
    }
    Try the above at the command line.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    13
    well, i cant use a int main()
    i am using int WinMain()
    ...

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    13
    example could be just like yours!!

  5. #5
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Bleh, WinMain...... OK, so post a "Hello, world" program with WinMain that you tried where std::cout doesn't print.

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    13
    Code:
    int WINAPI WinMain(HINSTANCE _hInst,HINSTANCE _hPrevInst,char* _cmdParam,int _cmdShow)
    {	
    
       std::cout << "HI" << std::endl;
        
       return 0;
    }

  7. #7
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    WinMain is for GUI applications... The output there is a little bit more complicated...

    Create a simple Command Line application project that uses int main

    and try there...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  8. #8
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    The -mwindows linker switch effectively stops console creation and ensures linkage with various windows specific libraries ie it's for windows gui applications. Vart's already mentioned the specificity of 'WinMain' as a gui entry point function.

    As a quick fix, use -mconsole to display the console; if your 'WinMain' program creates a gui window that, too, will be displayed.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. beginner's question :D
    By kingliaho in forum C Programming
    Replies: 5
    Last Post: 10-17-2008, 05:20 PM
  2. C beginners question
    By incipientmind in forum C Programming
    Replies: 5
    Last Post: 02-25-2008, 02:06 PM
  3. Beginner's Question: GDI CIRCLE
    By toonlover in forum Windows Programming
    Replies: 1
    Last Post: 09-09-2005, 10:28 PM
  4. Question type program for beginners
    By Kirdra in forum C++ Programming
    Replies: 7
    Last Post: 09-15-2002, 05:10 AM
  5. Stupid beginner's question
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 10-08-2001, 10:34 PM