Fine lemme explain myself better all of the classes you use for basic stuff here lemme post some code directly from a header file
Code:
namespace std
{
// 27.4.5 Template class basic_ios
/**
* @brief Virtual base class for all stream classes.
*
* Most of the member functions called dispatched on stream objects
* (e.g., @c std::cout.foo(bar);) are consolidated in this class.
*/
template<typename _CharT, typename _Traits>
class basic_ios : public ios_base
{
public:
//@{
/**
* These are standard types. They permit a standardized way of
* referring to names of (or names dependant on) the template
* parameters, which are specific to the implementation.
*/
typedef _CharT char_type;
typedef typename _Traits::int_type int_type;
typedef typename _Traits::pos_type pos_type;
typedef typename _Traits::off_type off_type;
typedef _Traits traits_type;
see all of the classes you use are in the std namespace notice these are just declarations.
>And when you #include a header file, it's an instruction for the compiler to include it in the contents in your source code, which means all the objects and functions of that header file are in the scope of your program, so how can they be 'protected' by namespace std?
Try to use any standard function without the std:: and see what happens when you compile. You'll get an error just cause your including it doesn't mean you saying your using that namespace in your program.
Im sorry im not clear maybe someone else could explain it better but this is the way I undertand it to be
Im' guessing the libs which are precompiled look similar in their use of the namespace. Heres a kinda lame example of such things
Code:
#include <iostream>
using std::cout;
using std::cin;
namespace loser
{
int subtract(int a,int b);
}
namespace loser
{
int subtract(int a,int b)//this would be in the lib
{
return a+b;
}
}
int subtract(int a,int b);
int main()
{
cout<<subtract(10,5);
cout<<loser::subtract(10,5);
return 0;
}
int subtract(int a,int b)
{
return a-b;
}