The short answer to your question is that the syntax you're using to output data is slightly off. If you chain together a bunch of output statements, the convention is to put the stream at the far left and to not repeat it. So rather than writing
cout << " " << endl << cout << "Hello world!" << endl;
~~~~~~~
just write
cout << " "<< endl << "Hello world!" << endl;
The reason you're seeing a 1
here is somewhat technical. The stream types all provide an overloaded operator that you can use to test for whether the stream is valid. For example, you can write something like this:
if (cout) {
// Everything is okay!
} else {
// I don't know how you did it, but you broke cout and you can
// no longer write anything to it!
}
(This is mostly commonly used for input streams, but output streams support this as well). As a consequence of this syntax, if you try inserting cout
into an output stream, C++ will first try to convert cout
to a boolean value and print that value instead. By default, booleans get printed as 1 (true) or 0 (false), so the 1 you're seeing is C++ saying "yes, this stream is up and running."
(Technically speaking the overloaded operator produces a void*
rather than a bool
, but I'll gloss over that detail for now.)
As a note, this behavior isn't supported in modern versions of C++ (C++11 and forward), and you'd actually get a compiler error if you tried doing this with a modern compiler. If possible, I would recommend upgrading your compiler version, which would have given you an error rather than generating code that doesn't do what you think it does.