Thread: Set type in C++

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    116

    Question Set type in C++

    I'm playing aground with some algorithms that use set will give the program clearer. For example, init a setA, after that, give some query like:
    <put a into setA><delete a in setA>
    <does a in setA> <does a not in setA>.....
    Pascal has this data structure, but I don't know does it exist on C++, and how to use it.
    please help me, please
    thanks

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You can #include <set> and use a std::set<T>, where T is the type of objects that you intended to store in the set.
    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

  3. #3
    Registered User
    Join Date
    Aug 2011
    Posts
    116
    I convert from Pascal to C/C++, so I have never use STD Library before. After I read about "set" on Wiki, they declare it begin with word: "template". And I google for what mean of "template", and OMG, they have many/many results about templates, each result say many/many things about it. It made me dizzy
    So, who can tell me simple, or give me some hint(links,note...) about template and how to use them, please I'm feeling very sick, now :|

    thanks

  4. #4
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by hqt View Post
    I convert from Pascal to C/C++, so I have never use STD Library before. After I read about "set" on Wiki, they declare it begin with word: "template". And I google for what mean of "template", and OMG, they have many/many results about templates, each result say many/many things about it. It made me dizzy
    So, who can tell me simple, or give me some hint(links,note...) about template and how to use them, please I'm feeling very sick, now :|
    thanks
    For std::set take a look at: std::set reference
    As for C++ and templates, you should really read through a book about C++ vice just jumping right into it. However we do have a good brief tutorial: Templates in C++
    Last edited by AndrewHunter; 09-09-2011 at 01:35 PM. Reason: ~
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You don't need to worry about the "template" part. It's just how it's declared and not how it's used.
    laserlight gave an example on how to create a set.
    Aside from that, if you want to know more, I think you should get a good book such as Accelerated C++ to journey into C++.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    Aug 2011
    Posts
    116
    OMG, after a long week playing aground with class,template,public,private,...(and many other keywords, maybe just have in OOP programming), at now, I have a new lesson, that I newly learnt: You don't need to know anything above(template,class...) to understand and use STD C++ library .
    On long road to have above statement, I see another funny point: the most effective document are not recommend C++ book lists on many sites I found. The easiest way to learn is lecture of many universities I have googled. For example: MIT, and standford. They are short, easy to understand, and specially, always say to focus point. (at least, because they write for student )

    At all, thank for all people here have given a vision how to learn C++ (although there a long way from know to understand )

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by hqt
    after a long week playing aground with class,template,public,private,...(and many other keywords, maybe just have in OOP programming), at now, I have a new lesson, that I newly learnt: You don't need to know anything above(template,class...) to understand and use STD C++ library
    Yes, at least for many of the common uses for the standard library.

    Quote Originally Posted by hqt
    On long road to have above statement, I see another funny point: the most effective document are not recommend C++ book lists on many sites I found. The easiest way to learn is lecture of many universities I have googled. For example: MIT, and standford. They are short, easy to understand, and specially, always say to focus point. (at least, because they write for student )
    Your mileage may vary for course material. Good academics are not necessarily good teachers, even if they genuinely are interested in teaching. Speaking of Stanford though, I recommend Accelerated C++, which has course material from a Stanford course involving C++ as a precursor.
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 05-23-2011, 02:04 PM
  2. Replies: 5
    Last Post: 01-24-2011, 05:37 AM
  3. error: array type has incomplete element type
    By gerger in forum C Programming
    Replies: 8
    Last Post: 10-05-2010, 07:40 AM
  4. Replies: 17
    Last Post: 03-06-2008, 02:32 PM
  5. Converting type string to type const char*
    By rusty0412 in forum C++ Programming
    Replies: 1
    Last Post: 07-11-2003, 05:59 PM