Like Tree1Likes
  • 1 Post By laserlight

Set type in C++

This is a discussion on Set type in C++ within the C++ Programming forums, part of the General Programming Boards category; I'm playing aground with some algorithms that use set will give the program clearer. For example, init a setA, after ...

  1. #1
    hqt
    hqt is offline
    Registered User
    Join Date
    Aug 2011
    Posts
    115

    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
    22,258
    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.
    msh likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    hqt
    hqt is offline
    Registered User
    Join Date
    Aug 2011
    Posts
    115
    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,866
    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 02: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
    Posts
    22,985
    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
    hqt
    hqt is offline
    Registered User
    Join Date
    Aug 2011
    Posts
    115
    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
    22,258
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 03: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, 08: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, 06:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21