Visual Studio cannot find my C++ hello world file - c++

#include <iostream>
int main()
{
std::cout << "Hello World" << endl;
return 0;
}
When I try to run this code, this message keeps popping up even though I copied and pasted straight from online. There are no build errors either.
Here's the error message

Nothing wrong with your code. Could be your antivirus deleting the exe before visual studio can start it. Try disabling your antivirus and run from VS again.
If not antivirus, then something else is deleting it.
Check if the exe shown in the path in your image is really there or not.

If you click Build -> Build Solution, you will get an error:
error C2065: 'endl': undeclared identifier.
I suggest you should try to use std::endl
Here is the code:
#include <iostream>
int main()
{
std::cout << "Hello World" << std::endl;
return 0;
}
And then you could try to run this code:

I added the file from the new file option not directly from the source file once I created the c++ project.

that error means that the .exe file is most likely still running. it may be that you closed it trough the "X" button, but the VS debugger is still running, so try clicking on the red square to stop it or go in your task manager and manually kill the process.
it may also be that the exe is opened by another process such as a hex editor which is denying further execution access to the file, but i have had this issue personally before and the fix above worked.

Related

C++ Hello world keeps giving me errors in Visual Studio 2019

I'm just trying to print hello world using C++ but all I get is build errors. The error list shows 412 errors and they're mostly "Cannot open source file" followed by a file name that I haven't heard of.
It also says the WindowsSDKDir property is not defined and the solution I found was to repair visual studio when I looked up this problem. I completed repairing visual studio and I have the C++ selected in the workloads.
Even when I select "Console App" during initial set up it'll end up giving me the same errors even though that is supposed to set up a basic environment for Hello World.
My code is simply just to print out hello world.
#include <iostream>
void output();
int main()
{
output();
}
void output()
{
std::cout << "Hello World!" << std::endl;
}
So I just uninstalled Visual Studio completely and then reinstalled it. I realized I could have just modified it using the installer, but basically after selecting the C++ workload I made sure every box was selected on the right hand side. I don't know if I needed it all but I just installed everything to be sure and it finally worked.

String variables don't work in Eclipse CDT

When I use string variables in Eclipse CDT (MinGW compiler) and I run the program, it doesn't show me anything. Here's my code:
#include <iostream>
using namespace std;
int main() {
string hw = "Hello, world!";
cout << hw << endl;
return 0;
}
So that doesn't show anything, but when I just do cout << "Hello, world!" << endl; it does work.
I also tried including <string>, <string.h>, "string" and "string.h" but still no success. The same code does work in VC++ and Codeblocks though.
I can reproduce this problem on my machine. The output does not appear. But it is not an output problem, but actually two problems before you get to main:
The program is failing to launch. If you try double-clicking on it in Windows Explorer, you will get an error message like this:
The program can't start because libgcc_s_dw2-1.dll is missing from
your computer. Try reinstalling the program to fix this problem.
Screenshot of above:
When launched from within Eclipse, this error message is silently swallowed, so how are you supposed to know!
Solutions/Workarounds
You need to get the environment correctly set up to launch the MinGW program because its DLLs are not installed on Windows PATH or other standard places DLLs are searched for.
Add C:\MinGW\bin to your PATH
Launch Eclipse from within a MinGW shell (has basically same effect as 1)
Run the program in debug mode, this causes the program to be launched as a child of GCC and that sets up
Other options (not tried by me) may include statically linking the offending library, see The program can't start because libgcc_s_dw2-1.dll is missing
File a CDT bug about the error message being hidden.
Extra info
If your program compiles, as I am sure it does based on your comments, changing the includes is probably irrelevant.
By adding an infinite loop around the couts I could immediately identify something more than simply an output not being shown was going on. Try the same thing on your machine, and also try running the program from within MinGW shell and from outside it.

Required file "tracker.exe" is missing

First time using Visual C++ in Visual Studio and I'm trying to teach myself C++ from some books. I am just trying to do a basic "Hello World" program and its getting a couple errors that I don't know anything about, as well as a bizarre warning. The missing source file seems to be standard and I can't figure it out.
The errors:
Error 2 error : Required file "tracker.exe" is missing.
Error 3 IntelliSense: cannot open source file "SDKDDKVer.h"
The warning:
warning MSB8003: Could not find WindowsSDKDir variable from the registry. TargetFrameworkVersion or PlatformToolset may be set to an invalid version number.
The code:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" ;
// This prevents the Console Window from closing during debug mode
cin.ignore(cin.rdbuf()->in_avail());
cout << "\nPress only the 'Enter' key to exit program: ";
cin.get();
return 0;
}
Any explanations or help would be huge! Thanks.
Here's a standard C++03 "hello, world!":
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, world!" << endl;
}
Turn off precompiled headers in the project settings. Make that compile without adding anything. Run it via Ctrl F5 (alternatively place a breakpoint on the final } and run it via the debugger, e.g. keypress F5).
If that doesn't work then you have configuration error. Then try first a new project. If that doesn't work, uninstall VS and reinstall it.

Open CV, C++: "Error: The application was unable to start correctly (0x0000005)."

I started working on OpenCV recently and configured OpenCV and MingW. I'm using Windows 7 OS. I am not using any IDEs for my programs. But still I am comfortable with the way I am doing the programs for now.
I wrote my first program and it compiled successfully but when I ran the .exe file it gave an Application error as :
The application was unable to start correctly (0x0000005). Click OK to close the application.
The following is the code I wrote:
#include "cstdlib"
#include "iostream"
#include "opencv2/highgui/highgui.hpp"
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("v.jpg", CV_LOAD_IMAGE_COLOR);
if (img.empty())
{
cout << "Error: Image cannot be loaded...!!" << endl;
system("pause"); //wait for a key press
return -1;
}
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE);
imshow("MyWindow", img);
waitKey(0);
destroyWindow("MyWindow");
return 0;
}
And for execution, I wrote a batch file as follows and executed it::
g++ -I"D:\opencv\opencv\build\include" -L"D:\opencv\opencv\build\x86\mingw\lib" ImageTest1.cpp -lopencv_core246 -lopencv_highgui246 -o ImageTest1.exe
ImageTest1.exe
pause
I also have added the following to the system path::
D:\MingW\bin;;D:\MingW\msys\1.0\bin;;D:\OpenCV\opencv\build\x64\mingw\bin;;
I tried changing the x64 to x86. But that didn't work.
Edit: I executed the .exe as admin and it says The application was unable to start correctly (0xc000007b). Click OK to close the application
I don't believe that you have reported the error code accurately. I do not believe that the error code contains only 7 hex digits. It contains 8. I believe that you have missed off the first digit, which I bet is c. In which case the error message really is:
The application was unable to start correctly (0xc0000005).
Now, that code is the NT status code STATUS_ACCESS_VIOLATION. When the system tells you that the application was unable to start this means that the error is happening during the loader's code. In other words, your code has not even started running yet. The error will be occurring in the DllMain function of one of your dependent DLLs.
Most likely there is some incompatibility between the different DLLs that are being loaded. In order to debug this further you'll probably need to debug the loading process. Start by running Dependency Walker in profile mode to find out which module's DllMain is raising the exception. Hopefully Dependency Walker will be able to point you towards the mismatch that exists in your dependent libraries.
Put system imports in <> brackets. This is for <cstdio> and <iostream>.
EDIT: I misread the error code. Please ignore the rest of my answer.
It seems windows cannot locate the libraries on startup.
My assumption is based on the 0x7B error.

The system cannot find the file specified. in Visual Studio

I keep getting this error with these lines of code:
include <iostream>
int main()
{
cout << "Hello World" >>;
system("pause");
return 0;
}
"The system cannot find the file specified"
The system cannot find the file specified usually means the build failed (which it will for your code as you're missing a # infront of include, you have a stray >> at the end of your cout line and you need std:: infront of cout) but you have the 'run anyway' option checked which means it runs an executable that doesn't exist. Hit F7 to just do a build and make sure it says '0 errors' before you try running it.
Code which builds and runs:
#include <iostream>
int main()
{
std::cout << "Hello World";
system("pause");
return 0;
}
The code should be :
#include <iostream>
using namespace std;
int main() {
cout << "Hello World";
return 0;
}
Or maybe :
#include <iostream>
int main() {
std::cout << "Hello World";
return 0;
}
Just a quick note: I have deleted the system command, because I heard it's not a good practice to use it. (but of course, you can add it for this kind of program)
I had a same problem and this fixed it:
You should add:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64 for 64 bit system
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib for 32 bit system
in Property Manager>Linker>General>Additional Library Directories
Another take on this that hasn't been mentioned here is that, when in debug, the project may build, but it won't run, giving the error message displayed in the question.
If this is the case, another option to look at is the output file versus the target file. These should match.
A quick way to check the output file is to go to the project's property pages, then go to Configuration Properties -> Linker -> General (In VS 2013 - exact path may vary depending on IDE version).
There is an "Output File" setting. If it is not $(OutDir)$(TargetName)$(TargetExt), then you may run into issues.
This is also discussed in more detail here.
This is because you have not compiled it. Click 'Project > compile'. Then, either click 'start debugging', or 'start without debugging'.
I resolved this issue after deleting folder where I was trying to add the file in Visual Studio. Deleted folder from window explorer also. After doing all this, successfully able to add folder and file.
I was getting the error because of two things.
I opened an empty project
I didn't add #include "stdafx.h"
It ran successfully on the win 32 console.