-
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? :confused:
BTW, I compiled it using VC++6. :rolleyes:
-
It may be returning the hex value of a pointer for some reason. :confused:
-
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. :(
-
Because it doesn't like you? :p :D
-
Might be. :D
I'm not crazy about M$ either... :)
-
BTW, you do know that you can do just "cout << string" (you don't need the operator), right?
-
Sure. :)
I was just playing with it.