What does include iostream do

0 votes

When I had started learning the basics of C++, I've always used the headings
 

#include <iostream> 
using namespace std;

I want to ask what is the point of iostream and Is it required every time as a heading?

Feb 8, 2022 in Others by Rahul
• 9,680 points
551 views

1 answer to this question.

0 votes

 In order to read or write the standard input or output streams, you need to include it by using:- 

int main( int argc, char * argv[] ) 
{
    std::cout << "Hello World!" << std::endl; 
    return 0; 
}


This given program will not compile unless you add #include <iostream> and also the second line is not needed:-

using namespace std;

This function will inform the compiler that the name symbol which is defined in the std namespace has to be brought in the scope of the program to let you remove the qualifier of the namespace. Below is an example:- 

#include <iostream> 
using namespace std; 
int main( int argc, char * argv[] ) 
{ 
  cout << "Hello World!" << endl; 
  return 0; 
}


You would have noticed that there is no longer a need to refer to the output stream with the entire qualified name std::cout and one can use the shorter name cout. I would personally recommend not to bring in all symbols in the namespace of a header file and rather you should individually select the symbols which you would want to be shorter so I would suggest you use this:

#include <iostream> 
using std::cout; 
using std::endl; 

int main( int argc, char * argv[] ) 
{ 
cout << "Hello World!" << endl; 
return 0; 
}


Please note that this is subjective and a matter of personal preference.

answered Feb 8, 2022 by Soham
• 9,710 points

Related Questions In Others

+1 vote
3 answers

What do I have to learn to become a software dev/engineer?

Hey, @Josh, Be Clear About Your End Goal. Software ...READ MORE

answered Jun 30, 2020 in Others by Gitika
• 65,890 points
1,367 views
0 votes
1 answer

can somebody explain me what does "passing by value" and "Passing by reference" mean in C#?

To answer your question, “passing by value” ...READ MORE

answered Feb 10, 2022 in Others by Rahul
• 9,680 points
741 views
0 votes
1 answer

What does enctype='multipart/form-data' mean?

When any POST request is made, then ...READ MORE

answered Feb 10, 2022 in Others by Rahul
• 9,680 points
1,117 views
0 votes
1 answer

What are canonical URLs and how do they affect your SEO?

canonical URLs are distinct URL used to ...READ MORE

answered Feb 11, 2022 in Others by narikkadan
• 63,720 points
440 views
0 votes
1 answer

setuptools: build shared libary from C++ code, then build Cython wrapper linked to shared libary

There is a seemingly undocumented feature of setup that ...READ MORE

answered Sep 11, 2018 in Python by Priyaj
• 58,100 points
641 views
0 votes
1 answer

setuptools: build shared libary from C++ code, then build Cython wrapper linked to shared libary

There is a seemingly undocumented feature of setup that ...READ MORE

answered Sep 21, 2018 in Python by Priyaj
• 58,100 points
2,332 views
0 votes
1 answer

How to pass large records to map/reduce tasks?

Hadoop is not designed for records about ...READ MORE

answered Sep 25, 2018 in Big Data Hadoop by Frankie
• 9,830 points
1,396 views
0 votes
1 answer

Invalid method parameters for eth_sendTransaction

params needs to be an array, try {"jsonrpc":"2.0","method":"eth_se ...READ MORE

answered Sep 28, 2018 in Blockchain by digger
• 26,740 points
1,795 views
0 votes
1 answer

What does the "map" method do in Ruby?

The .map method will take an object ...READ MORE

answered Feb 8, 2022 in Others by Soham
• 9,710 points
1,066 views
0 votes
1 answer

What is dependency injection?

According to James Shore, the term “Dependency ...READ MORE

answered Feb 8, 2022 in Others by Soham
• 9,710 points
668 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP