0

C++ beginner questions

I just started learning C++ and when I code, it always starts with: #include <iostream> using namespace std; Why is that? What does it do and what does it mean? Do I always have to start that way when coding? Another question is about int main () Why do I declare main as an integer like I would for an assigned value?

4th Mar 2019, 3:58 AM
Lucas
2 odpowiedzi
+ 5
Aaaaaand, yes and no. If you read those threads provided, you should understand that, in short: - <iostream> is responsible for providing the standard input/output functionalities for your program. - "using namespace std" specifies that certain objects/functions you use, like cout and cin, are from the std namespace. (std::cout, std::cin) This means that if your program does not deal with input and output streams, you don't need to use <iostream>. If you can specify the std namespace in front of every standard object, then "using namespace std" is not required. You can have a program which just do: int main() { int a = 39; } The above is definitely a valid program, but without <iostream>, there's not much to do without input and output, right? As for main() returning integer, it is specified as part of the language standard. It is compulsory for main to return int. http://www.stroustrup.com/bs_faq2.html#void-main
4th Mar 2019, 4:14 AM
Fermi
Fermi - avatar