std namespace

guys I need your help
I can't understand how I to use std namespace

I hope to help me in fastest time
Use a reasonably current C++ implementation.

Use standard (non-deprecated) C++ headers.
http://en.cppreference.com/w/cpp/header

Prefix names in the library with std::
For instance,
1
2
std::cout << "hello world\n" ; // #include <iostream>
auto len = std::strlen( "abcd" ) ; // #include <cstring> 
whenever you start coding

1
2
3
4
5
6
7
8
#include <iostream>

void main()
{
  std::cout<<"Hi buddy!!\n";

  std::cin.get();
}


putting

using namespace std;

inside your code will allow you to avoid using the prefix std::

and access directly to the namespace variables and methods.

this:
1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;
void main()
{
  cout<<"Hi buddy!!\n";

  cin.get();
}


will compile exactly as the above.
cout

is located inside the std namespace, btw.

same as many other methods and variables.

std::string and std::vector<T> for example. Both are located in string.h and vector.h libraries.
@kaidto

It is normal practice to not do what you are saying. It is OK for beginners - but sooner or later they need to break this bad habit. This is because using std namespace; brings in the whole std namespace - polluting the global namespace, which can cause naming conflicts. Go with JLBorges's advice.

The other thing to do is have:

1
2
3
4
5
//#includes

using std::cout;
using std::cin;
using std::endl;


for frequently used things, use std:: for other things.


Also - main returns an int, not void.
@rero92 (I can't understand how I to use std namespace


Use it as your own namespace.:)
TheIdeasMan

It was my fault, but I realize that now. It happens to be more decent to declare each using statement.
Topic archived. No new replies allowed.