Visual Studio not creating .exe for C++ Program.

Samrat Banerjee 21 Reputation points
2021-07-29T13:34:40.693+00:00

Visual Studio not creating .exe for C++ Program. As a student, I have Visual Studio 2022 Preview. I installed it just yesterday and have the workloads,

  1. ASP.NET and Web Development
  2. Node.js development
  3. .NET Desktop Development
  4. Desktop Development with C++
  5. Universal Windows Platform Development

I am writing the programs strictly following the rules gives in my book. It worked in Turbo C++ but it is not working here. Please help me if there are any settings I need to do (I have not changed any settings) or I require more workloads and maybe some workloads need to be left out. Please help as soon as possible as I require it immediately.

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,518 questions
Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
935 questions
{count} votes

Accepted answer
  1. WayneAKing 4,921 Reputation points
    2021-07-30T01:39:47.187+00:00

    Some observations:

    (1) As already mentioned by others, your source file must be
    part of the project being built. If you haven't done that then
    a Build/Rebuild may show success from the build as it will have
    built an empty project (minus your source code.)

    (2) If there are any missing parts of a build - such as occurs
    when there are compile or link errors or no code provided - then
    no exe will get created. So naturally you will get an error
    when you try to Run it - there isn't any exe to run.

    (3) Avoid using Run or Run without debugging when learning
    how to use VS - it just creates confusion as most starters
    often only look at the end result - the last error message
    received - and fail to check the earlier messages from the
    build which show where the problems began. Always do a Build
    or Rebuild first, and only use Run/Run without debugging when
    all build errors (and preferably all warnings as well) have
    been corrected.

    (4) You mention Turbo C++ and the code you posted would
    be common for very old versions of Turbo C++. But the C++
    language has changed significantly since your examples
    (and book) were created. The code you posted will not
    compile without error in VC++ or any other compilers
    from the past decade or two.

    Specifics;

    #include <iostream.h>
    

    is no longer correct as all C++ headers have had the
    .h extension removed. The correct form now is:

    #include <iostream>
    

    Also:

    cout << "Hello...";
    

    The streams are now in the std namespace, so that must be
    specified for cout, cin, etc.

    std::cout << "Hello...";
    

    There are alternative ways to specify the namespace such as:

    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        cout << "Hello...";
    }
    

    OR

    #include <iostream>
    
    using std::cout;
    
    int main()
    {
        cout << "Hello...";
    }
    

    Note that main should always return an int, as prescribed by
    the C++ Standard. Some compilers will still accept void main()
    but it should be avoided.

    If you are using a book published 20+ years ago then you
    really need to use a much more current text.

    • Wayne
    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Castorix31 81,461 Reputation points
    2021-07-29T13:40:58.66+00:00

    I don't have VS 2022, but with 2019, you can just follow MSDN tutorials, like :
    Walkthrough: Creating a Standard C++ Program (C++)