Thread: List of Include functions

  1. #16
    coder
    Join Date
    Feb 2008
    Posts
    127
    Quote Originally Posted by Elysia
    Yes, some headers include other dependencies, so sometimes you get headers for "free."
    so is it possible that another compiler won't find <string> if I didn't include it in my source?
    Quote Originally Posted by King Mir
    Again, I disagree...
    Ok, no matter. Everybody have to choose the right way himself, due to his own experience.
    So my opinion is not against yours, it is just a different point of view.

  2. #17
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Quote Originally Posted by carlorfeo View Post
    so is it possible that another compiler won't find <string> if I didn't include it in my source?
    Yes, that's exactly right.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  3. #18
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The compiler might not find std::string. It won't even search for <string>, which is a header, unless you include it.

    Exact notation is important in net-based communication.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #19
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    In my opinion, learning how to implement e.g. a linked list should happen before learning "ready-to-use" c++ lists or such containers. They are very useful, but a beginner will probably use them in a wrong way (like I did myself with strings), if he doesn't understand how they exactly work.
    Logically, that means that you should learn how to implement the stuff in <iostream> before you write your first "hello world" program.

    After all, a beginner will probably use std::cin and std::cout in a wrong way if he does not understand how they exactly work.

    But this is putting the cart before the horse. Clearly, "hello world" programs are popular introductions to programming languages because they teach basic syntax and how to write some output to the console.

    The next step is often a program that accepts input, say a variant of "hello world" with a personalised greeting. This teaches about basic input, and yet even at this point there is no mention that from the previous lesson, std::cout is a std::ostream which is a typedef for std::basic_ostream<char> which is a subclass of std::basic_ios<char, std::char_traits<char> > which is a virtual base... at which point no one wants to learn C++ any more because it is just too hard, but we have not even mentioned std::ios_base yet, much less talked about how to implement these class templates.

    Ok, no matter. Everybody have to choose the right way himself, due to his own experience.
    So my opinion is not against yours, it is just a different point of view.
    Your own experience shows that learning how to use something first is often easier than learning how to implement it first, as I have pointed out with iostreams. Likewise, as advocated by Koenig and Moo in their book Accelerated C++, learning how to use std::vector before introducing arrays and pointers is usually a better pedagogical technique than teaching arrays and pointers first.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #20
    coder
    Join Date
    Feb 2008
    Posts
    127
    There are many misunderstandings about my opinion, probably my english is not so clear.
    Logically, that means that you should learn how to implement the stuff in <iostream> before you write your first "hello world" program.
    I said the opposite instead: I said that using <iostream> stuff would be enough for a c++ beginner.
    After all, a beginner will probably use std::cin and std::cout in a wrong way if he does not understand how they exactly work.
    I meant to say that a beginner will probably use the STL stuff (string, list, vector) in a wrong way if he doesn't know how they work internally.
    For instance, it would be uselessly expensive to create a string just to pass a single character to a function. There are many other examples you may imagine.

    Finally I believe that it doesn't matter so much what one learns first: the different experiences shown in these posts just tell me that.
    In my case, I prefer to start from the harder things and then, once I got them, make my life easier using available tools.
    Perhaps your case is the opposite, and this doesn't mean that one way is better than the other.

  6. #21
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    For instance, it would be uselessly expensive to create a string just to pass a single character to a function.
    This has nothing to do with how strings work internally, and everything with understanding the concept of a string and the concept of a single character. Which is probably more difficult if English isn't your native language.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #22
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I said the opposite instead: I said that using <iostream> stuff would be enough for a c++ beginner.
    That's my point: you believe, and rightly so, that <iostream> is enough for a beginner. Likewise, <vector> and <string> is enough for a beginner, until enough knowledge is gained to use the low level facilities that these classes abstract away.

    In my case, I prefer to start from the harder things and then, once I got them, make my life easier using available tools.
    But <iostream> makes life easier for us. If you prefer to start from the harder things, then why start by using std::cin and std::cout? Why not start by implementing them yourself, or by programming a GUI?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #23
    coder
    Join Date
    Feb 2008
    Posts
    127
    Quote Originally Posted by laserlight
    ...Why not start by implementing them yourself, or by programming a GUI?
    Sure, why not?
    I hope I will have the time to make also these things you are suggesting.

  9. #24
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Too late. You already used them.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  10. #25
    coder
    Join Date
    Feb 2008
    Posts
    127
    Quote Originally Posted by CornedBee
    Too late. You already used them.
    Damn! XD

    Quote Originally Posted by Technical_13
    For instance I know that <iostream> gives me cOut and cIn, is there anything else it offers?
    Back to the beginning, these two links might answer your question clearly:
    http://www.cplusplus.com/reference/
    http://en.wikipedia.org/wiki/C%2B%2B...andard_headers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting linked list please help with CODE
    By scarlet00014 in forum C Programming
    Replies: 3
    Last Post: 09-27-2008, 11:24 PM
  2. Need help sorting a linked list. Beginner
    By scarlet00014 in forum C Programming
    Replies: 1
    Last Post: 09-27-2008, 06:16 PM
  3. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  4. help with finding lowest number entered
    By volk in forum C++ Programming
    Replies: 12
    Last Post: 03-22-2003, 01:21 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM