You are not logged in.
I use the following C++ code:
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!";
return 0;
}But I compile it with g++ helloworld.cpp, and ./a.out gives nothing. What is wrong with the code, or is the compiler broken, and how do I fix it?
Last edited by SealsRock12 (2018-07-28 12:41:00)
-- SealsRock12
Offline
The code should be fine, but there are countless other possibilities other than the compiler, unless you have other reason to suspect it. Have you done something odd to replace g++? Are you using the g++ from the repos?
If so, then how about some diagnostics. `ldd a.out` and `strace ./a.out` would be a fair start.
Also, what is the exit code from a.out?
Last edited by Trilby (2018-07-28 02:23:53)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
That's most likely a printout issue w/ the next PS1 because there's no newline, try
cout << "Hello, World!" << endl;Offline
That's most likely a printout issue w/ the next PS1 because there's no newline, try
cout << "Hello, World!" << endl;
I added that then compiled it and it worked. Thank you.
Marking as solved.
-- SealsRock12
Offline
Just to make that absolutely clear: the endl is NOT required to write to stdout, the issue is with your shell (config), not the code.
However you very often want to add newlines (so much that the "echo" command defaults to it)
Offline