0

I'm new in programming. I run simple C++ program, like this:

#include <iostream>
int main(int argc, char *argv[]) {
std::cout<<"What?";}

by using the terminal by typing g++ Program.cpp.

No error is returned after compiling, but the standard output is not shown on the line, which I think it sohould return What? as typed after std::cout<<.

What can be the cause why the standard output is not shown in terminal?

1

2 Answers 2

2

Well the g++ command compiles the program. You also have to link and build the program.

Try gcc -o program Program.cpp

After that you'll have to run it:

./program

Also, you forgot using namespace std;

1
  • It's a bad practice to use using namespace std; If you have, for example, a method that is named like a method in the std library, you can have unexpected results.
    – Cesar
    Jun 5, 2017 at 1:07
2

Actually, it should be something like this:

sneetsher@mx5:~/Desktop$ g++ Program.cpp 
sneetsher@mx5:~/Desktop$ ./a.out 
What?sneetsher@mx5:~/Desktop$

Notice where What? is hiding, because you didn't include any new line \n or <<endl;!!!

Not the answer you're looking for? Browse other questions tagged .