Results 1 to 7 of 7

Thread: namespace std problem?

  1. #1
    Sc0rp
    Guest

    Talking namespace std problem?

    Hi,

    I'm learning C++ now and I'm now lerning about streams and stuff.
    I was playing with iostream and a weird thing happened:
    Code:
    #include <iostream.h>
    
    int main()
    {
    	cout.operator <<("Wazzup\n");
    	return 0;
    }
    Output:

    Wazzup
    Press any key to continue

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    	cout.operator <<("Wazzup\n");
    	return 0;
    }
    Output:

    0046B01CPress any key to continue



    Anyone has any idea why this happens?

    BTW, I compiled it using VC++6.

  2. #2
    It may be returning the hex value of a pointer for some reason.

  3. #3
    Sc0rp
    Guest
    Yes, this is what it does exactly.

    Code:
    // added a '*' before the string:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    	cout.operator <<(*"Wazzup\n");
    	return 0;
    }
    This asks for the value that is in that memory address.
    When I run the program it prints '87' on the screen, which is exactly the ASCII value of 'W', the first character in the string.

    I just don't know why it does that.

  4. #4
    Because it doesn't like you?

  5. #5
    Sc0rp
    Guest
    Might be.
    I'm not crazy about M$ either...

  6. #6
    BTW, you do know that you can do just "cout << string" (you don't need the operator), right?

  7. #7
    Sc0rp
    Guest
    Sure.
    I was just playing with it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width