1
C - C++ / Re: problem with Cout statement
« on: March 27, 2013, 10:13:05 PM »
for using namespace std;
It really depends where you want to put it. It deals with scope.
putting using namepsce std; above int main() makes it file scope, meaning that the std namespace will be applied to everything outside the main function (other functions as well).
Putting it inside the main, means that it will be only applied WITHIN the main function. And not to any other functions.
The best practice in reality is to do std::cout <<
Since that is too hard to type std:: you can do this:
using std::cout;
and put that in your main().
Reason for this is that then there will be no namespace conflicts. Since you are working with small and simple projects, you may only want to keep it at using namespace std;
Once you start working on large projects with multiple namespaces, you will want to restrict your use of using namespace std; and start doing things like std::cout<< or using std::cout;
It really depends where you want to put it. It deals with scope.
putting using namepsce std; above int main() makes it file scope, meaning that the std namespace will be applied to everything outside the main function (other functions as well).
Putting it inside the main, means that it will be only applied WITHIN the main function. And not to any other functions.
The best practice in reality is to do std::cout <<
Since that is too hard to type std:: you can do this:
using std::cout;
and put that in your main().
Reason for this is that then there will be no namespace conflicts. Since you are working with small and simple projects, you may only want to keep it at using namespace std;
Once you start working on large projects with multiple namespaces, you will want to restrict your use of using namespace std; and start doing things like std::cout<< or using std::cout;