question

SamratBanerjee-2809 avatar image
0 Votes"
SamratBanerjee-2809 asked PhlexPayPhlexybleSolutions-1849 commented

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

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++vs-debugging
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Try selecting “Rebuild Solution” from Build menu. Then select “Error List” from View menu and check if there are errors. Show some details, maybe including your code.

0 Votes 0 ·

119079-2021-07-29-1.png


119105-2021-07-29-2.png


119080-2021-07-29-3.png




Here they are...
Just before showing "No .exe file" it shows a win terminal window which auto closed in 1 sec.
Plz help.

0 Votes 0 ·
2021-07-29-1.png (109.1 KiB)
2021-07-29-2.png (125.6 KiB)
2021-07-29-3.png (114.5 KiB)

The "problem" may be tied to the location where c++ projects place the executable folder.
By default it is placed in:
$(SolutionDir)$(Platform)\$(Configuration)\
This means that unlike common sense implementations that place the output files within the project folder, c++ projects place the executable outputs relative to the solution folder. So in your scenario the executable is not located in Project1/Project1/<x64 or whatever your processor is>/<filename>.exe
if is located in Project1/<x64 or whatever your processor is>/<filename>.exe


0 Votes 0 ·
WayneAKing-0228 avatar image
2 Votes"
WayneAKing-0228 answered SamratBanerjee-2809 commented

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






· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Sorry for the late reply but thank you. It has worked. Thak You again.

0 Votes 0 ·
Castorix31 avatar image
0 Votes"
Castorix31 answered Castorix31 edited

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


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I have tried that but to no avail.

0 Votes 0 ·
Castorix31 avatar image Castorix31 SamratBanerjee-2809 ·

You apparently did not add a source file from your screenshots...

After having added it :
"The .cpp file appears in the Source Files folder in Solution Explorer, and the file is opened in the Visual Studio editor."

1 Vote 1 ·