+ 3

How can we create our own library just like iostream?

25th Oct 2017, 1:59 PM
Shashank Shekhar
Shashank Shekhar - avatar
4 Answers
+ 5
Yes, thats the convention. To store the declarations separately, you create a seperate C++ file with the same name as the header and write the definitions in it. Don't use main even here. Do include the header created before, like you will do in the normal main program. And yes, don't include this C++ file in your main program.
25th Oct 2017, 3:02 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 4
Steps : Windows. 0) Windows+R. 1) Type 'notepad' inside the box. 2) When the untitled file opens, Save it with a name but change the extension to .h instead of .txt 3) Write your code inside the header. Do not add main. Just add function definitions, constant declarations, classes, etc. 4) Use the functions inside any C++ file in the same location, by adding this : #include"name_of_file.h". // Replace the name_of_file with any name.
25th Oct 2017, 2:20 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 2
Thanks @KinshukVasist. But according to conventions, only declaration should be in the header file and its definition should be in the implementation file. So, how do I do that?
25th Oct 2017, 2:54 PM
Shashank Shekhar
Shashank Shekhar - avatar
+ 1
Thanks a lot @KinshukVasist
25th Oct 2017, 3:04 PM
Shashank Shekhar
Shashank Shekhar - avatar