dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Hello world prgram not runing

  1. #1
    Join Date
    Mar 2017
    Posts
    12

    Hello world prgram not runing

    I wrote this hello world program from tutorial yesterday and it was running but now it is not. I have windows 10, and using visual studio 2017. When I go to Deub tab, the start debugging option can not be highlighted, it is gray. How can I run this again?

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    	cout << "Hello World" << endl;
    
    	system("pause");
    	return 0;
    	
    }
    Last edited by 2kaud; June 4th, 2019 at 06:48 AM. Reason: Added code tags

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,410

    Re: Hello world prgram not runing

    Does the .exe file exist? If not - try to rebuild.
    Victor Nijegorodov

  3. #3
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,207

    Re: Hello world prgram not runing

    @Ketanco
    Have you created a Windows Console Project or is something else?
    Name:  new_project.jpg
Views: 56
Size:  29.7 KB
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: http://codexpert.ro/blog/author/ovidiu-cucu/

  4. #4
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,148

    Re: Hello world prgram not runing

    Check the properties of your solution and see that your executable is set as the startup project.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,011

    Re: Hello world prgram not runing

    Make sure the build mode is set to Debug, not Release.

  6. #6
    Join Date
    May 2019
    Posts
    35

    Re: Hello world prgram not runing

    You should add:

    Code:
    #include <Windows.h>
    You should also ensure your project is set to run as a Windows Application and not a Console Application.

    Windows Applications often don't accept 'cout <<'. You'd need to use:

    Code:
    MessageBox(NULL, "Hello World!", "Hello!", MB_OK);
    If you're not using WinAPI then make sure your program is running as a CONSOLE APPLICATION. You can use 'cout <<' with Console Applications with no problems.

    Project > Properties > Linker > First option set it to 'Console Application' or 'Windows Application' depending on how you want to code...
    Last edited by Arianax; June 4th, 2019 at 04:26 AM.

  7. #7
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,730

    Re: Hello world prgram not runing

    Quote Originally Posted by Arianax View Post
    You should add:

    Code:
    #include <Windows.h>
    You should also ensure your project is set to run as a Windows Application and not a Console Application.

    Windows Applications often don't accept 'cout <<'. You'd need to use:

    Code:
    MessageBox(NULL, "Hello World!", "Hello!", MB_OK);
    If you're not using WinAPI then make sure your program is running as a CONSOLE APPLICATION. You can use 'cout <<' with Console Applications with no problems.

    Project > Properties > Linker > First option set it to 'Console Application' or 'Windows Application' depending on how you want to code...
    The program in post #1 is a console program so cout should be used and #include<windows.h> and MessageBox() should not used.

    As the OP has not posted further since the post #1, I'm guessing that the problem has been solved.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.1.6)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)