• Advertisement

Archived

This topic is now archived and is closed to further replies.

Is it the compiler or me?

This topic is 5141 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I came across an issue with my compiler or me, i dont know which, when i was learning about the using namespace command. I had the followring code, one set uses a namespace declaration and the other set uses a namespace directive. The namespace directive causes errors in the compiler. #include <iostream> int main() { using namespace std; cout << "Message..."; return 0; } and #include <iostream> int main() { using namespace std::cout; cout << "Message..."; return 0; } The above gives me errors. I am using the Bloodshed C++ Compiler. Is the compiler wrong, or is it me?

Share this post


Link to post
Share on other sites
Advertisement
Try:
using std::cout;
instead of
using namespace std::cout;

Share this post


Link to post
Share on other sites
Thanks guys...

using std::cout works fine

Now im just wondering why the book told me something different...

Share this post


Link to post
Share on other sites
#include <iostream>
int main()
{
using namespace std;
cout << "Message...";
return 0;
}

into

#include <iostream>
using namespace std;

int main()
{
cout << "Message...";
return 0;
}

Share this post


Link to post
Share on other sites
quote:
Original post by xidis
Thanks guys...

using std::cout works fine

Now im just wondering why the book told me something different...


Code printed in books - especially for C++ - is notorious for being wrong.

Share this post


Link to post
Share on other sites

  • Advertisement