Thread: STL - Easy to Use or Not?

  1. #1
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812

    STL - Easy to Use or Not?

    Is it just me, or does anyone else find 'STL' inconvenient to use?

    I do use it, but find myself pouring through pages of overloaded functions, only to find what I want to do isn't supported, but everthing else I wouldn't of dream is.

    For example, you can't do this:

    std:string s = 'a';

    Instead, after you have to do this:

    std:string s(1, 'a');

    or even this:

    std:string s;
    s += 'a';

    I wrote some code recently which converted between doubles and strings using ostringstream and istringstream, while having some control over the formatting. The amount of work this wasn't true - I could have wrote my own stuff to do this far more easily.

    Has any one figured out how to use locales with STL? Because I can't.
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> I do use it
    Using it is the best way to learn it and get used to its methodology

    >>...but find myself pouring through pages of overloaded functions, only to find what I want to do isn't supported
    I use http://www.sgi.com/tech/stl/ and MSDN as a quick reference for looking things up.

    >> Has any one figured out how to use locales with STL?
    Yes..."figured out" via this.

    >> I could have wrote my own stuff to do this far more easily.
    Not with the same degree of flexibility

    gg

  3. #3
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    Thanks for the reply. Guess you find STL OK? I'm not saying that it's bad, I'm only suggesting that it seems to make hard work of doing some really simple things. Guess I'm in a minority, as usual.

    >> I could have wrote my own stuff to do this far more easily
    >Not with the same degree of flexibility

    I meant I could have written my own float to string routines for the purposes at hand from scratch in less time that it took me to figure out how to use ostringstream and istringstream and get them working properly. For example, the exact meaning of precision various depending upon which STL documentation you read.

    Thanks for the links about locales and streams. It's something I'll look into.
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    Since I figured out iterators I love STL, I hope I never write another data structure class again. (list, heap, stack, etc..)

  5. #5
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    I find the STL very useful, and while it is not exactly easy to understand the interface, I don't know of any interface that is naturally intuitive. Once you get used to it, you become used to how it works, and it makes it that much easier to get things done.

    It might have been faster for you to write your own routines this time, but the more you use a library the more comfortable with it you'll be, and in the future when you need something more complicated it will be nice to have such a widely used, tested, and established solution that you are already familiar with.

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Since the Standard Template Library is indeed a library, using 'it' i assume means using some of its parts. In which case I recommend reviewing all your options before using them. I find that std::string is very useful but it is not always necessary (yes go ahead and flame me as you will).

    So it all depends on what you need.

  7. #7
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Quote Originally Posted by Davros
    For example, you can't do this:

    std:string s = 'a';
    But you can do this:

    Code:
    std::string s = "a";
    Just use " instead of '. You just need to get used to things I guess.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  8. #8
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    >Just use " instead of '. You just need to get used to things I guess.

    That wasn't the point. I was using this as an example of how certain very basic features are absent/overlooked in STL. I would have thought a constructor which accepts a single char in a string class is very important. In any case, your suggestion isn't always be possible - I wasn't just picking on a pedantic point.

    >yes go ahead and flame me as you will

    I wasn't intending to flame anyone.

    And I wasn't really asking for help with how to understand STL.

    I just thought it would make a good topic for discussion.

    But thanks for the replies.
    Last edited by Davros; 06-15-2004 at 08:35 AM.
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  9. #9
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    I don't think it's complicated to handle strings, convert numbers, printing etc.

    But yesterday I thought that it'd be possible to overload ostream to create a nice socket class. I didn't quite figure out how to overload ostream, it looked quite complicated.

    Anyway, now it struck me that doing this would be possible:
    Code:
    class Socket
    {
    //...
    template<typename T)
    Socket& operator<<(const T& data)
    {
    	std::stringstream s;
    	s << data;
    	sendDataToConnection(data.str());
    	return *this;
    } 
    };
    I really like the STL. It should be larger, though.

    Code:
     
    std::string s = 'p';		  //It is very strange that this doesn't work
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  10. #10
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Quote Originally Posted by Codeplug
    >> Has any one figured out how to use locales with STL?
    Yes..."figured out" via this.
    "This" is also good for learning how to extend iostreams.

    gg

  11. #11
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    I think that this is also an excellent book.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  12. #12
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    715
    By the way, I'm trying to connect to irc.dal.net but no success. Which port should I use?

  13. #13
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I'm trying to connect to irc.dal.net but no success. Which port should I use?
    6667. But DALnet isn't very active, especially not our channel. I prefer to frequent Undernet or EFnet in #c and #c++, as do a few other members of Cprogramming. If you want, stop by there and look for Robc.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Java vs C to make an OS
    By WOP in forum Tech Board
    Replies: 59
    Last Post: 05-27-2007, 03:56 AM
  2. C Formatting Using STL
    By ChadJohnson in forum C++ Programming
    Replies: 4
    Last Post: 11-18-2004, 05:52 PM
  3. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  4. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM