Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualmolehill mountaineer

Posted 16 September 2013 - 11:10 AM

you should avoid "using namespace std;" - this tells the compiler "look in the namespace std for all types" and can be a problem when you start using other namespaces.

 

For example: if you have a namespace "gameStuff" and there's a type called "cout" in there the compiler will be looking in the wrong namespace.

Because 'std' contains a 'cout' type the compiler won't know that something is wrong and the program will compile, then you get to look for the bug

(it uses std::cout when it should have been gameStuff::cout)

 

You can either:

- put using namespace std in the main function (that's what nightcreature was talking about). This will tell the compiler "using this namespace but only for this function")

- be more specific with your using statements, that is:

using std::cout;
using std::cin;
using std::stringstream;

instead of the much more broad "using namespace std".

 

 

If you want to chat with us you can! After you've logged in there will be a link to the chat page. You'll find it at the top of the page, below the search box. You can also login with an IRC client but I don't recall the address at the moment.


#2molehill mountaineer

Posted 16 September 2013 - 11:10 AM

you should avoid "using namespace std;" - this tells the compiler "look in the namespace std for all types" and can be a problem when you start using other namespaces.

 

For example: if you have a namespace "gameStuff" and there's a type called "cout" in there the compiler will be looking in the wrong namespace.

Because 'std' contains a 'cout' type the compiler won't know that something is wrong and the program will compile, then you get to look for the bug

(it uses std::cout when it should have been gameStuff::cout)

 

You can either:

- put using namespace std in the main function (that's what nightcreature was talking about). This will tell the compiler "using this namespace but only for this function")

- be more specific with your using statements, that is:

using std::cout;
using std::cin;
using std::stringstream;

instead of the much more broad "using namespace std".

 

 

If you want to chat with us you can! After you've logged in there will be a link to the chat page. You'll find it at the top of the page, below your username and reputation points. You can also login with an IRC client but I don't recall the address at the moment.


#1molehill mountaineer

Posted 16 September 2013 - 11:08 AM

you should avoid "using namespace std;" - this tells the compiler "look in the namespace std for all types" and can be a problem when you start using other namespaces.

 

For example: if you have a namespace "gameStuff" and there's a type called "cout" in there the compiler will be looking in the wrong namespace.

Because 'std' contains a 'cout' type the compiler won't know that something is wrong and the program will compile, then you get to look for the bug

(it uses std::cout when it should have been gameStuff::cout)

 

You can either:

- put using namespace std in the main function (that's what nightcreature was talking about). This will tell the compiler "using this namespace but only for this function")

- be more specific with your using statements, that is:

using std::cout;
using std::cin;
using std::stringstream;

instead of the much more broad "using namespace std".

 

 

If you want to chat with us you can! After you've logged in there will be a link to the chat page. You can also login with an IRC client but I don't recall the address at the moment.


PARTNERS