Why “utilizing namespace std” is used after together with iostream | by Danoja Dias | Break the Loop


On this Article we provide you with detailed Info on Why “utilizing namespace std” is used after together with iostream | by Danoja Dias | Break the Loop

Damage Days

If you’re a beginner to c++ and attempting to grasp a really fundamental c++ program to print one thing, you’ll have this query. You higher learn this text earlier than going into this. When you’ve got some information of printing in c++ simply learn this.

To start with, you have to know what c++ namespaces are. In programming, we can not have variables, capabilities, and many others with the identical title. So to keep away from these conflicts we use namespaces.

So for one namespace we are able to have one distinctive title and that very same title may also be utilized in one other namespace. Following instance exhibits two namespaces.

We now have used the identical title for variables and capabilities right here. We are able to name these A::printX() which is able to give the end result 5 and B::printX() which is able to give the end result 10. There is no such thing as a naming conflicts since we use namespaces. Following code, block exhibits easy methods to use namespaces.

“utilizing namespace std” means we use the namespace named std. “std” is an abbreviation for traditional. So which means we use all of the issues with in “std” namespace. If we don’t need to use this line of code, we are able to use the issues on this namespace like this. std::cout, std::endl.

If this namespace shouldn’t be used, then pc finds for the cout, cin and endl and many others.. Pc can not establish these and subsequently it throws errors.

So now you will have an concept on namespaces. Let’s go to the unique query why namespace is used, when we now have all within the iostream header file. iostream is a file that has all of the issues like cout, endl and and many others is outlined. If we have to use them we have to add that file. So principally #embody means copying and pasting the code in that file to your code. But when we attempt to use cout, endl in our code with out specifying the namespace it should throw an error, as a result of these are outlined within the std namespace within the iostream.h file like following. Following is dummy of iostream.h file. This provides you with an concept about how that is outlined.

So after we run a program to print one thing, “utilizing namespace std” says when you discover one thing that’s not declared within the present scope go and test std.

So now you will have the reply why each statements

utilizing namespace std;

are used. It’s as a result of pc must know the code for the cout, cin functionalities and it must know which namespace they’re outlined.

In order a abstract, why you want each the header file and the namespace to run a easy c++ program, as a result of pc must know the definition of the code of the functionalities. It’s outlined within the header file. So header file must be included. namespace is required as a result of if a functionalities like cout is used, however not outlined within the present scope pc must know the place to test. so namespace must be included. As a result of we’re writing the code outdoors the std namespace.

#namespace #std #together with #iostream #Danoja #Dias #Break #Loop