Cout Does Not Display

Please bear with me; I'm new to C++ and the Linux environment. My simple program compiles without errors but does not display "TEST" as it should. Am I missing any files that should be installed? I am using CentOS.

1
2
3
4
5
6
7
8
#include <iostream>

using namespace std;

int main()
{       cout << "TEST";
	return (0);
}

Last edited on
Two things:
Firstly you do NOT need the parentheses around 0 for your return value, just "return 0;" is fine.
Secondly, how are you running the file? If you just run the executable, it will close before you can see it say "TEST", however, if you run it from a command line that should work, or you can stop the program from exitting until you press enter by adding "cin.get();", such as:
1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;
int main()
{
  cout << "TEST";
  cin.get();
  return 0;
}
I run it from the command line. I followed your code but it's still the same.

Here's the display in the terminal:

[root@localhost Desktop]# g++ test.cpp -o test
[root@localhost Desktop]# test
[root@localhost Desktop]#
You shouldn't be doing this as the root user.

As a security measure, the current directory is not usually part of your path (especially for root).

1
2
$ g++ -o test test.cpp
$ ./test


There may also be a "test" command in your shell or path. Type
 
which test

If you get a result other than command not found, the test command it found was run instead of your program. This is another reason to use ./test
Hotaru, you are right =) I should've used ./ test Thank you very much for your help. =)
Topic archived. No new replies allowed.