locked
How to know what to write in headers? RRS feed

  • Question

  • Hi,

        as you can see from my name i am dumb at programming :) .... but i am willing to learn so, i would be grateful if someone could really answer my question?✪‿✪ like for example there is iostream.h ..... when i search for they say its old now the latest id iostream library... but the thing is how to know what to write in each of the headers???

    P.S.   PLEASE do help as i need to know for my project :D

    Regards,

    dumbATprogramming(for real) :D

    will be waiting for your replies ^_^

    Thursday, March 15, 2012 6:16 AM

Answers

  • >for example there is iostream.h ..... when i search for
    >they say its old now the latest id iostream library...
    >but the thing is how to know what to write in each of
    >the headers?

    If you're referring to the iostream header, the answer is
    you *don't* write anything in that header or in any other
    header from the compiler's libraries. You use them via an
    #include when needed by your program. You should *never*
    alter any of these headers.

    If you mean what do you put in your *own* headers, then
    it's entirely up to you. You put whatever serves the
    requirements of your application.

    If you're still confused then I suggest you do a Web
    search for "C++ headers" and read whatever you find
    in tutorials, ebooks, etc.

    - Wayne
    • Marked as answer by Helen Zhao Thursday, March 22, 2012 1:17 AM
    Thursday, March 15, 2012 6:29 AM
  • Which compiler and version are you using?
    Always specify, as answers may be different
    for different compilers or versions.

    In all recent C++ compilers, iostream is in the
    std:: namespace. So you need to specify that.
    There are at least three different ways to do it:

    (1) Specify std:: every time you use an iostream class
    or member: std::cout, std::cin, std::endl

    e.g. - std::cout << "Hello Woild!" << std::endl;

    (2) Make the std:: namespace global:

    #include <iostream>
    using namespace std;

    Then you can use cout, cin, endl without std:: in front:

    e.g. - cout << "Hello Woild!" << endl;

    (3) Specify std:: in advance for each term that needs it:

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

    Here too you can use cout, cin, endl without std:: in front:

    e.g. - cout << "Hello Woild!" << endl;

    - Wayne

    • Proposed as answer by MTdewMan98 Sunday, March 18, 2012 5:24 PM
    • Marked as answer by Helen Zhao Thursday, March 22, 2012 1:17 AM
    Thursday, March 15, 2012 6:56 AM

All replies

  • >for example there is iostream.h ..... when i search for
    >they say its old now the latest id iostream library...
    >but the thing is how to know what to write in each of
    >the headers?

    If you're referring to the iostream header, the answer is
    you *don't* write anything in that header or in any other
    header from the compiler's libraries. You use them via an
    #include when needed by your program. You should *never*
    alter any of these headers.

    If you mean what do you put in your *own* headers, then
    it's entirely up to you. You put whatever serves the
    requirements of your application.

    If you're still confused then I suggest you do a Web
    search for "C++ headers" and read whatever you find
    in tutorials, ebooks, etc.

    - Wayne
    • Marked as answer by Helen Zhao Thursday, March 22, 2012 1:17 AM
    Thursday, March 15, 2012 6:29 AM
  • wow that's really fast... thank you so much... 

    ok will give it try and see :)

    thank you,

    dumbATprogramming

    Thursday, March 15, 2012 6:34 AM
  • but my programming has cout and cin as well as endl , and when i try to debug it... it doesnt recognise it and says got errors :(

    help me please & thank you,

    dumbATprogramming :)

    • Proposed as answer by CSTech Wednesday, April 4, 2012 12:41 AM
    • Unproposed as answer by CSTech Wednesday, April 4, 2012 12:41 AM
    Thursday, March 15, 2012 6:39 AM
  • Which compiler and version are you using?
    Always specify, as answers may be different
    for different compilers or versions.

    In all recent C++ compilers, iostream is in the
    std:: namespace. So you need to specify that.
    There are at least three different ways to do it:

    (1) Specify std:: every time you use an iostream class
    or member: std::cout, std::cin, std::endl

    e.g. - std::cout << "Hello Woild!" << std::endl;

    (2) Make the std:: namespace global:

    #include <iostream>
    using namespace std;

    Then you can use cout, cin, endl without std:: in front:

    e.g. - cout << "Hello Woild!" << endl;

    (3) Specify std:: in advance for each term that needs it:

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

    Here too you can use cout, cin, endl without std:: in front:

    e.g. - cout << "Hello Woild!" << endl;

    - Wayne

    • Proposed as answer by MTdewMan98 Sunday, March 18, 2012 5:24 PM
    • Marked as answer by Helen Zhao Thursday, March 22, 2012 1:17 AM
    Thursday, March 15, 2012 6:56 AM
  • but my programming has cout and cin as well as endl , and when i try to debug it... it doesnt recognise it and says got errors :(
    In general, in order to get help, you need to post both your actual code (relevant parts only if it is long) and the precise error message(s) that you received.
     
    In this case, I think Wayne has guessed correctly what problem you are having, but this will not always be possible.
     

    David Wilkinson | Visual C++ MVP
    Thursday, March 15, 2012 11:40 AM
  • As Wayne already explained you each and every thing in a proper way . But Still i think this is not going to help you a lot . So a good advice pick a good book on C++ and start reading so that you can come to know how to write code and about header file and method etc define in those header file.

    Thanks


    Rupesh Shukla

    Thursday, March 15, 2012 2:41 PM
  • ok thx :D
    Friday, March 16, 2012 3:29 AM
  • #include <iostream>

    this usually handles cout, cin and endl

    Wednesday, April 4, 2012 12:42 AM