You are not logged in.

#1 2018-07-28 00:59:35

SealsRock12
Member
Registered: 2018-04-03
Posts: 83

[SOLVED] I think my C++ compiler is broken.

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

#2 2018-07-28 02:23:08

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,543
Website

Re: [SOLVED] I think my C++ compiler is broken.

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

#3 2018-07-28 06:26:11

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,843

Re: [SOLVED] I think my C++ compiler is broken.

That's most likely a printout issue w/ the next PS1 because there's no newline, try

cout << "Hello, World!" << endl;

Offline

#4 2018-07-28 12:40:33

SealsRock12
Member
Registered: 2018-04-03
Posts: 83

Re: [SOLVED] I think my C++ compiler is broken.

seth wrote:

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

#5 2018-07-28 12:43:43

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,843

Re: [SOLVED] I think my C++ compiler is broken.

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

Board footer

Powered by FluxBB