Click here to Skip to main content
15,040,212 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello Everyone!;

I am learning C++ and I wanted to use my PC instead of a mac just for preference. When i try to run the code, I get this error message;

(This is my code)
#include <iostream>
using namespace std;

int main() {
  cout << "Hello World!";
  return 0;

(This is the error)

g++.exe: error: program.cpp: No such file or directory
g++.exe: fatal error: no input files

Any help would be appreciated;

Thank You

What I have tried:

I have watched every youtube video and tried every suggestion in the comments, yet nothing has seemed to fix it. Would anyone be able too help me out? If possible; a step by step method would be great. I have mingw, I have updated the path about 20 times and I still cant get it to run. When I run it from command prompt; It can't find my folder on the desktop to be able to run it.
Updated 12-Jan-21 2:29am

The error is trying really hard to tell you what the problem is: it can't find the file you told it to compile.

Have a look at the GCC options list and compare that to the command you are executing: Using the GNU Compiler Collection (GCC): Overall Options[^]
Member 14892814 18-Jul-20 10:32am
How do i know what code to look for?
OriginalGriff 18-Jul-20 11:32am
Start at the beginning: what - exactly - do you do to try and compile your app?
Member 14892814 18-Jul-20 11:52am
Once i finished the code; i typed “g++ program.cpp”
Then a.out

Program.cpp is the name of my file.
OriginalGriff 18-Jul-20 12:08pm
And if you type "dir" do you see it in the current directory?
Member 14892814 18-Jul-20 12:12pm
When i type "dir" i see a lot of things come up; but not anything called "g++ program.cpp" . The only things i see come up related to coding is; .vscode. If there's a way i can send it to you in private would that be easier?
OriginalGriff 18-Jul-20 12:55pm
Which is why you don't get a compilation.
You either have to be in the right directory (i.e. the one with your source code in it) or tell the compiler where to look (i.e. provide a full or relative path to the actual file).
Member 14892814 18-Jul-20 13:00pm
How do i go about doing that? I added a path but i don’t know if i added it right.
the path i have is;

I don't know what to put after it, nor how to figure out what to put after. I'm getting a fatal error in my command prompt which the video says is right...
You need to save the source file from VSCode into program.cpp, in some local directory of your account. You then move to that directory and call g++ with its name. The way I do it is to open a terminal window in VSCode (Ctrl-') and move to my code directory in that window. I then save the source file into that directory and call the compiler from there. So the sequence is:
Ctrl-' -> opens the terminal window
cd mycodedirectory -> in the terminal window

Mouse click into the source code window and do File -> Save As, to save the program as program.cpp in mycodedirectory

mouse click into the terminal window and type the compile command:
g++ program.cpp
CPallini 16-Dec-20 2:05am
After trying a bunch of tutorials.
I just closed all the files I was trying to run and and gone File>Open Folder
Selected the folder where those files where... can't say I understood, but...problem solved
Max Łuc 26-Jul-21 12:17pm
I was literally struggling over this for 2 days now, thanks a lot <3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900