|
-
Aug 13th, 2001, 11:02 AM
#1
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.
-
Aug 13th, 2001, 11:12 AM
#2
Member
It may be returning the hex value of a pointer for some reason.
-
Aug 13th, 2001, 11:16 AM
#3
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.
-
Aug 13th, 2001, 11:35 AM
#4
-
Aug 13th, 2001, 11:39 AM
#5
Might be. 
I'm not crazy about M$ either...
-
Aug 13th, 2001, 12:08 PM
#6
Member
BTW, you do know that you can do just "cout << string" (you don't need the operator), right?
-
Aug 13th, 2001, 12:10 PM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|