My terminal in VS Code won't print anything or give me an error. Don't know why it is not printing - c++

Just installed Visual Studio Code with C/C++ IntelliSense... (Microsoft) and Code Runner extensions. I am also using MinGW. This code refuses to print to my terminal.
#include<stdio.h>
int main(){
printf("Hello World");
}

While viewing this file press Ctrl+Shift+P and type Run Code and press enter.
You should see a terminal opened with OUTPUT tab and see the result or an error.
If an error occurs publish it alongside with your question.

Related

No output in console from std::cout in Visual Studio 2019 x64 Native Tools Command Prompt

I have some C++ executables which contain various std::cout outputs.
In Visual Studio 2019 x64 Native Tools Command Prompt, when I run these executables, there is no output displayed on the console.
If I redirect the output to a file, the output is indeed printed to the file.
The following program for example does not output anything to the console:
#include <iostream>
int main (int argc, char** argv) {
std::cout << "Hello world" << std::endl;
}
Is there some setting or variable I need to set in order to see the output in the console itself ?
According to the code you provided, my console program can output normally.
I suggest you could verify that the Visual C++ developer command prompt is set up correctly. In the command prompt window, enter cl and verify that the output looks something like this:
For more details about how to compiling a Native C++ Program on the Command Line, I suggest you could refer to the Doc: Walkthrough: Compiling a Native C++ Program on the Command Line

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!" freeze in c++

I tried to compile a simple Hello World in C++ to test that my Visual Studio 2013 on my Windows 10 works well but I've a problem. My program compile but when I run, it freeze. It's an empty Win32 Console Application with a "main.cpp" :
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!";
return 0;
}
If I launch it from Visual Studio in debug (with "Run"), Visual Studio freeze and I need to kill its task.
If I launch it with the executable or with "Run without Debugging", nothing appear, "System" process doesn't want to free the execution and I can't recompile without restart the computer because of that.
I am confused. If somebody have an idea of what's happening, please help me.
Update 1 : I repair my installation. Same problem. Breakpoint doesn't help. It seems to freeze before. And also no trace of a task in the task manager when launched without debugging.
It was my antivirus' fault (in my case, Avast). I made it ignore my Visual Studio projects and it works. Solved by #Blastfurnace.

Debugging C++ in Netbeans

I am very new to work c++ Programs with Netbeans IDE in Ubuntu. I wrote a simple Hello World Program and tried to debug it using step Into. When I Click Step Into Option From Debug Menu I got new window opened in the name of " Diassembly(main) " . The Debug process didn't reach my source code line at any way. I repeatedly click Step Into Function At last the process got end Without Tracing my source code line. But In the Debug output window I got the Correct Result.
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello";
cout<<"World";
}
Why This process Control goes to the Diassembly (main) window ? How to rectify this problem ?
You must compile with -g option, otherwise the debugger won't be able to stop on a breakpoint. As for disassembling window - I can't reproduce that (I'm on Netbeans 7.4 in Ubuntu 13). You should just close the window if you don't need it.
First, you have to toggle a break point in your code by clicking on the line number of the line you want to stop in source window, if you did not. Then hit Debug.
Don't step into function that you not build from source, just step over it.
Pehaps that there is an answer here (i can't comment sorry)
"No source available for main()" error when debugging simple C++ in Eclipse with gdb

Xcode not showing anything in console with C++

I was just trying to use Xcode for a very small C++ project, and wanted to see
some prints in the console, the thing is I did not see anything.
I tried to run a very simple code instead:
#include <iostream>
int main (int argc, char * const argv[]) {
std::cout << "Hello, World!\n";
printf("here");
return 0;
}
but still, nothing in Xcode console.
any idea why?
EDIT:
adding snapshot of the program:
EDIT 2:
found this,
and it's working:
How do I run a C++ program in Xcode 4?
That should work fine. Are you sure that you had the console displayed? Try command-shift-C or choose View->Debug Area->Activate Console.
If that doesn't help, try running your program from a Terminal window. Does the program display the expected output?
It sounds like when you created a new project (File > New > Project... ), you selected "C/C++ Library". Since libraries don't output to the console directly, that explains why Run was greyed out for you and running it doesn't output to the console.
Instead, you need to create a new project and select "Command Line Tool" template in the Application section, and build your program from there.
Your image doesn't show that you ran the program, only that you built it. Look at the Log Navigator (the last one, ⌘7) and see if there are any logs for 'Debug one' after 'Build one'. To run the program use Product > Run or ⌘R.
Try pressing Shift+Command+R. That should compile your program and open it in a terminal window.
maybe you need to add "\n" after "here"
I don't know why but it works for me.
Hope someone can explain it for me.