Dev cpp - Error while running: not a valid Win32 application - c++

I have recently started with C++ and am using Dev cpp as my IDE. But whenever I compile and run the program for Dev cpp, the program compiles successfully but while running the .exe file I get the following error:
--------------------------------
Failed to execute "C:\Users\Karan Gandhi\Desktop\Untitled1.exe":
Error 193: %1 is not a valid Win32 application.
Press any key to continue . . .
Here is my program:
#include <iostream>
using namespace std;
int main() {
cout << "Hello world";
return 0;
}
Please Note: I can successfully run the program from the terminal manually by just opening the file in the terminal: "C:\Users\Karan Gandhi\Desktop\Untitled1.exe"
Is there any way to fix this? Thank you!

Related

HelloWorld.exe (process 12192) exited with code 0 issue

I'm a beginner in learning C++ programming and just started to use IDE VS Community 2022.
I've created the new project corresponding to tutorial and when i run it i get the messege in the console:
C:\Users\??????\source\repos\HelloWorld\x64\Debug\HelloWorld.exe (process 12192) exited with code 0.
The code is
#include <iostream>
int main()
{
std::cout << "Hello, world!";
return 0;
}
I know it's not an error, but is there some of solution to remove this message?
Thank you in advance!
This is a feature of the IDE you are using. Try to run your program using the command line prompt directly and the message will not be displayed.

Notepad++ NppExec console warning, need explanation "C++"

I've tried using Notepad++ to code c++ and followed a few tutorials on youtube, here's what I did:
-Installed gcc/g++ compiler using mingw64
-Installed NppExec plugin on N++
-Typed in the following compilier script and saved as C++:
NPP_SAVE cd $(CURRENT_DIRECTORY) g++ $(FILE_NAME) cmd /c $(CURRENT_DIRECTORY)\program.exe
Anyways whenever compiling a program, for example a simple program
#include <iostream>
using namespace std;
int main(){
cout << "Online\n";
system("pause"); //So that cmd doesn't disappear immeadiately on running.
return 0;
}
The console displays the following warning:
"C:\Users\pc\Desktop\Courses\Projects\C\program.exe' is not recognized as an internal or external command, operable program or batch file."
My question is, When I run the program on cmd, it runs perfectly but the error displayed during linking says that the folder does not exist in %PATH%
Any explanation?
Thank you!
Ok so, what I basically did was change the script,
cmd /c $(CURRENT_DIRECTORY)\program.exe
To be later
cmd /c $(CURRENT_DIRECTORY)\a.exe
the console worked fine and even received input
Here is a link to a similar problem:
How to compile/execute C++ code from within Notepad++

C++ code run in debug console rather in terminal in vs-code

I wanted to execute code in terminal not in debugger
After downloading all the c/c++ extension in vs-code.
code
#include<iostream>
using namespace std;
int main()
{ int UserInputOccur;
cout<<"helloworld";
cin>>UserInputOccur;
cout<<UserInputOccur;
return 0;
}
All the compilation and debugging done in debug console only till
( First user input i.e When first cin>>UserInputOccur; and then the code in terminated with helloworld1020=thread-exited,id="3",group-id="i1"
If you are using Linux you can write your code in a file, such as main.cpp.
Then you can open terminal -> go to the directory of the file -> run command g++ main.cpp -o main.
Now you can run your code on terminal with command ./main

Exe file not opening

I am trying to learn C++ now and created a Hello World program. When I compile it on Linux using g++ and it works perfectly fine. When I compile it on Windows using the Build tools, it still compiles the code into machine code, but I can't open the executable. I used the Microsoft build tools as a compiler. The code was:
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!";
}
The output should be: Hello, World!
**Question already answered:
The program closes because it is not run in cmd. To prevent the program from crashing add
```system("pause");```
at the end**
The executable is showing the correct output on the terminal, but that terminal closes that fast that you don't even realise it.
I'd advise you to open a command prompt, go to the directory where the executable is located and launch it over there. You'll see the desired output.
it possibility because
the app closes immediately after ouputing
add system("pause");
on the end
Its not that you can't open that exe file.
Once you click on that file, it opens up and does its work and closes.
To prevent your exe file from getting closed after doing its operation, you can add following line at the end of the main function :
getchar();
And now once you open your exe file, it wont close automatically, you will need to press "enter" to close it.
#include<iostream>
using namespace std;
int main(){
cout<<"hello world";
getchar();
}

Hello World C++

Every time I try and run the Simple Hello World program in C++, I build it and it says nothing to build for FirstProject. The code looks correct, I'm using MinGW as my compiler, etc. Every time I try to run the program, instead of printing the output, it just terminates. Anyone have a clue?
#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
try these commands:
g++ -o hello_world.exe hello_world.cpp
./hello_world.exe
MinGW works same as gcc on linux so all commands which work on linux should work on MinGW
In cygwin, the following steps should work.
Save the contents to file HelloWorld.cc.
Go to the directory where you saved the file.
Execute make HelloWorld
Execute ./HelloWorld.exe
If that doesn't work, something is really not right.
Are you running it from the command line or an IDE? Sometimes an IDE will open a terminal and close it too fast for you to see, or you'll just see a flash. Try running it from the command line so you'll be able to see if it printed anything before exiting the program.
Tried and tested using MinGW in windows 10 command prompt.
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello, World!"<<endl;
system("pause");
return 0;
}
Image of command prompt output
Save the contents to file HelloWorld.cpp
Go to the directory where you saved the file.
Execute make HelloWorld
Execute ./HelloWorld.exe