no "hello world " output (c++) - c++

If I run the code::blocks default console c++ "hello world" app (see below), I only see this in the console that opens :
Process returned 0 (0x0) execution time : 0.011 s
Press any key to continue.
I don't see "hello world". What could be wrong ?
If I run the ./helloworld.exe with cygwin, I do see "hello world". But I don't see it with cmd or powershell.
The app :
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}

There is a related discussion you might want to check out here:
http://www.tomsguide.com/forum/244674-49-basic-program
It could be a matter of the program executing too quickly, per the forum I referenced above, but that seems like an odd reason. You might try what they recommend (pause, etc.), but you may also have an issue with your compiler or how your properties are set up.
For cmd, check this out:
https://www.thecrazyprogrammer.com/2015/09/how-to-run-c-and-cpp-program-in-cmd.html
For the command line/Windows prompt, check this out:
https://msdn.microsoft.com/en-us/library/ms235639.aspx

Thanks to #George.
Solution was to remove the -mwindows compiler flag.
But to make it work, I needed to delete the .exe before building again.

Related

Why is my C++ code outputting NSString literals rather than plaintext?

I know this question seems odd, as NSString doesn't exist in C++. Yet, for some reason, when I run the following code:
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
I see the following output:
#"Hello, World!\r\n"
The C functions printf and puts show similar behavior. I also see the same output if I store the text as a std::string and then display that.
I have no idea how to even start troubleshooting this. What is going on?
I figured it out a while ago but I forgot about my own question.
In the debug window, it just displays output like that. It only gets formatted like that in debug mode; if I compile it and run the executable from the command line, then it works as expected.

Why is there no Console Window showing up whilst debugging

Alright so I have been trying to fix this for a while, but with NO SUCCESS, I've come here to search for help instead. I'd appreciate it!
So basically, when I debug with gdb it should give me a console window saying "Hello World" (cause that is what I wrote in my code) right? Well you guessed, there is no console window for me.
This is the code i've written:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
This is supposed to give me an "Hello World" output in the console window but it is not, cause the console window is not even there when I debug. I've double checked almost everything and I can't find ANY SOLUTION at all.
Thanks for listening as this is very frustrating for me.
If you are using VSCode in launch.json file with a configuration of debug execution you can use
"externalConsole": true
which allows you to see your output not in the embedded terminal.

C++ in VSCode - Getting Started

I'm having trouble getting a simple C++ script to run in VSCode (I'm new to both). I followed these instructions, and the status bar displays "C++" on the bottom right of the screen, next to the smiley face. I then ran the following script:
#include <iostream>
using namespace std;
main()
{
cout << "Hello World!\n";
return 0;
}
When I run it, the script's path flashes on the output screen and disappears. I expected it to display "Hello World" in the output.
I can run the script from the command window (I'm in Ubuntu) and the output file behaves as expected when executed.
Your program prints message to STDOUT and exits. Add some kind of wait (you can read STDIN for example) if you want to see its output.
PS: Why do you call your program "script"?

execl - No memory available to program now (OS X / XCode / C++)

I'm trying to execute a very simple program that runs "ls" command
Im working under Mac OS 10.7, with XCode and C++
This is the code:
#include <iostream>
using namespace std;
int main(void)
{
cout << "Hello world" << endl;
execl("/bin/ls","ls",NULL);
return 0;
}
It crashes after following output
Hello world
No memory available to program now: unsafe to call malloc
I tried to google it but no luck, any ideas on what I might be doing wrong?
This is just "my opinion"
From man page:
The exec family of functions replaces the current process image with a
new process image.
It could be that it tries to replace the debugger process and so it crashes (the app is run from Xcode..). If you execute the app from command line it works...
Seems to work fine:
http://ideone.com/8AoZ3
But seems like on your platform some sort of weird recursion is taking place. Can you change your call to:
execl("/bin/ls","/bin/ls",0);
I know this may not be exactly what you want to do, but the following SO question is using execv to execute echo:
how-to-create-a-process-on-mac-os-using-fork-and-exec

Can I see the program output in Qt-Creator?

I am writing a simple OpenGL program with Qt Creator which basically creates a QGLWidget, shows it, and runs the application loop. I usually like debugging more with diagnostic messages turned on and off by preprocessor symbols that using an actual debugger and watches etc. In Qt Creator we have a tab called Application Output, but all I see there is "Starting xxx.exe. xxx.exe exited with code 0". No output from either std::cout or std::cerr. Now I know I could start my application from cmd.exe (yes, I am using Windows, love it :P) and see the output there but I wish I could see the output directly from the IDE. Is that possible? Thanks
Usually the Application Output pane works fine. Are you sure that you would see the output from cmd.exe (have you actually tried?)? It's usually turned off for UI applications to avoid console windows from popping up. Try CONFIG += console. Also check if you see qDebug() messages in the Application Output.
simply #include <QDebug>
and then use qDebug instead of cout like
qDebug() << "you just clicked ok";
also this works
#include <QTextStream>
QTextStream out(stdout);
out << "\nHello World!\n";
adding CONFIG += console in the .pro file didn't work for me. I wonder why?
i just discovered that i've to add "endl;" for cout to work like
cout << "print this" << endl;
Alternatively, you can check the "run in console" setting in the Project->Run options. This will open a new console window and display all console output there (if CONFIG += console is used of course).
I know that this answer do not answer the original question, but since when searching for "No application output" we found this answer...
See the following answer: https://stackoverflow.com/a/26325743/808101
This only apply to qDebug() and similar functions (not direct output to stdout/stderr).
In my case, I have to set QT_ASSUME_STDERR_HAS_CONSOLE environment variable to 1 in QtCreator in order to see qDebug() messages inside "Application Output" window.
Try:
Tools -> Options
Under the "General" tab of "Environment" change the terminal entry from:
x-terminal-emulator -e
to
xterm -e