-3

After compiling lots of programs with g++, suddenly endl; is exhibiting strange behavior. In addition to a newline, I also get console output of a hexadecimal number. Thinking perhaps I had some memory leak issue I rebooted my Linux Mint Debian Edition (up to date) running within VMWare on top of Windows. Problem persists. Below is my g++ version (unchanged since previous normal output) and a test program with output below that.

g++ ver (Debian 4.8.2-1) 4.8.2

void my_test_function(void)
{
  // cout << "my_test_function is working" << cout << endl;
  cout << "my_test_function is working\n" << cout << endl;
}

Test output:

my_test_function is working 0x600ea8
Claudio
  • 2,191
  • 24
  • 49
  • 1
    It's not `endl` doing that and as of C++11, this shouldn't compile. – chris Jul 23 '14 at 03:32
  • 10
    Hint: You're printing `cout` to itself. – Jonathan Potter Jul 23 '14 at 03:33
  • 1
    Try to not use `using namespace std;`, it's a bad practice. – denisvm Jul 23 '14 at 03:38
  • @chris [see it working!](http://coliru.stacked-crooked.com/a/406720866a9eaf20) – M.M Jul 23 '14 at 03:56
  • @MattMcNabb, Yeah, libstdc++ hasn't made the change (since last I checked anyway). [libc++ has](http://coliru.stacked-crooked.com/a/18e43c3c3d50c662) – chris Jul 23 '14 at 04:19
  • Since no one has explained beyond "it's wrong", pre-C++11, `std::ios` has an `operator void *` inherited by `std::ostream` that returns a null pointer if `fail()` returns true and a non-null pointer otherwise. – chris Jul 23 '14 at 04:22

3 Answers3

1

You have an incorrect "cout" in the statement

Try following

void my_test_function(void)
{
  cout << "my_test_function is working" << endl;
}
Ankit Patel
  • 1,191
  • 1
  • 9
  • 9
1

I can't comment there sorry

The line just has to be like as follows

cout << "my_test_function is working" << endl;
Shivam
  • 457
  • 1
  • 6
  • 15
1

Fixed code:

cout << "my_test_function is working" << endl;

std::cout is the object of ostream. You need study the signature of ostream's operator<< and definition of std::cout.

Usagi Ito
  • 483
  • 7
  • 16