Normal C++ code in Qt doesnt build and run - c++

I am using Qt under linux, if it matters.
I ran successfully under Geany (a simple c++ compiler) the following:
//my first program in C++ Hello World!
#include <iostream>
using namespace std;
int main ()
{cout << "Hello World!";
return 0;}
I opened Qt source file and copied the exact same code and i can't build or run.
Thank you for your responses to this simple problem.

If you did what I think you did, you didn't open this as a project, which is the only place where you can build and run (I think).
Try the following.
- Open Qt Creator.
- Go to File->New File or Project
- At the bottom, select "Qt4 Console Application"
- Select a location; it might be nice to create a folder called "hello_world" or something to store the project in.
- A new project will have been created. Copy over the main.cpp file in sources with your code. My code looked like this:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!\n";
return 0;
}
Hit "Build All"
Hit "Run"
This worked for me. Hope this helps!

Related

I can't run basic C++ program " Hello World " in Visual Studio

I'm learning C++ as first programming language and I can't figure out how to run Hello World program. I was googling for solution but I did not find any.
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!";
return 0;
}
Unable to start program
'C:\Users/thom/Desktop/C++/Visual/firstproject/Debug/Hello World.exe'.
The system cannot find the file specified.
If you create a .cpp file in File > New > File > C++ File?
If so, the path is not included in the project directory, causing the compiler to fail to find the file.
The correct way is to create a cpp file in the project directory under Explorer.As shown below:
You can modify the name of the .cpp, and don't modify the default location.
Now you can try to build and run the executable.
Try Build -> Rebuild Solution, find the executable in the path shown at the output to run it.
You can also try pressing Ctrl+F5 to build and run

C++ "Hello world" shows no output

I installed Codeblocks on my Windows 10 computer. To check that everything works fine, I first compiled the simple C program
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello world!\n");
return 0;
}
That works without problem but when I try the C++ equivalent:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return(0);
}
Then the "command prompt" window opens but no output is shown. I can see in taskmanager that the program is running but as said without any visible output. I also tried running the program directly from the command line but with the same effect. Anyone any ideas?
I found the issue. There was still an older version of MinGW installed in a different folder. I deleted all instances of MinGW, and codeblocks as well. Adter I reinstalled codeblocks everything worked as it should.
This Guy solved similar problem with Codeblocks.
Remove the following Global compiler setting:
-Wl,-subsystem,windows

Codeblocks won't run executable

somehow codeblocks decided not to run any new programs anymore. All I get is a black screen when running. Take for example the simple "Hello World" program. That will not even run. It compiles just fine without any error. All i see though when codeblocks opens is a black screen.
I tried looking online for help. It looked like this
Can't find file executable in your configured search path for gnc gcc compiler
would fix the problem. It didn't though.
This was my code:
#include <iostream>
using namespace std;
int main(){
cout<< "Hello World!" << endl;
return 0;
}
I don't know what happened and why. Sincerely hoping for an answer.

C++ Visual Studio 2010 "Unable to start Program"

I've been looking arund and i can't find the problem for this. Whenever i try to debug my project, i get this error
Unable to start program 'C:/Users/.../project/.dll'
All i did was create a new application than put this
// This is the main DLL file.
#include "stdafx.h"
#include "asddsa.h"
/*
* File: main.cpp
* Author: Arhowk
*
* Created on March 22, 2013, 10:15 PM
*/
#include <cstdlib>
#include <iostream>
using namespace std;
/*
*
*/
using namespace std;
void main()
{
cout << "Hello World!" << endl;
cout << "Welcome to C++ Programming" << endl;
}
any help? I can provide more debug info if needed, but cant find any. Running VS2010 Express on a W7 x64 machine
You shoud create an exe project like "Win32 Console Application"
"C:/Users/.../project/.dll" looks wrong, Right click your project, select "Properties", check "General->TargetName", "Debugging->Command" and "Linker->General->Output File"
When you created your project, what type did you create? It looks like you created a DLL project. DLLs can't be ran directly, you need to have an exe that will load one or more DLLs.
If you create an exe project, you should be able to run it directly to test your code.

XCode C++ Ignoring Main Function

I have most bizarre and probably simple to solve problem but it's driving me crazy.
I'm using XCode 4, I've started with an empty project added a new file main.cpp containing:
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
cout << "Hi There!" << endl;
}
Then I added a target called main and added main.cpp to it's sources and compiled and run to be greeted with:
Hello, World!
In return.
Why is XCode adding and compiling it's own main function and how to I tell it to use mine?
It also compiles and runs successfully with an empty main.cpp.
Thanks.
First try cleaning and rebuilding.
If that doesn't work sounds like there is another file with a main in it that is being included in the build.
In the Project File, go into the "Build Phases" tab, and see what is listed under "Compile Sources". The source of your problem might be there.