StringList?

This is a discussion on StringList? within the C++ Programming forums, part of the General Programming Boards category; I'm trying to write a StringList class....is there any example you know? Is it better to use the <list> class? ...

  1. #1
    Registered User Moni's Avatar
    Join Date
    Oct 2002
    Location
    Dhaka, Bangladesh.
    Posts
    104

    Question StringList?

    I'm trying to write a StringList class....is there any example you know?

    Is it better to use the <list> class?

    I'm trying to do it by taking pointer to the pointer...double pointer format.

    wchar_t **strlst;

    Now having trouble to make the copy constructor or equal to operator overloading.....don't know how to do it.....need any sample or example!
    We all are the components of a huge program...... the programmer is always debugging us with His debugger.

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Internally, you want it to be represented as a list<string>, but you want to be able to build the string list from a wchar_t **? Perfectly reasonable. Check out this c-faq link on passing multi-dimensional arrays (list of strings) to functions http://c-faq.com/aryptr/ary2dfunc3.html

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  3. #3
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    What exactly are you trying to do? If you need a linked list of strings, and assuming this isn't a homework assignment with restrictions on using the standard libraries, a std::list<std::string> is exactly that. Google std::list, and google std::string if you don't know what either one is.

    Otherwise, there's a million variations on what you *could* do, depending on exactly what you need.

    P.S. Also, in case you don't understand what 'linked list' means, and this is what you're actually supposed to work with, I recommend googling "linked list tutorial".
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  4. #4
    Registered User Moni's Avatar
    Join Date
    Oct 2002
    Location
    Dhaka, Bangladesh.
    Posts
    104
    well...it must be Unicode supported.
    We all are the components of a huge program...... the programmer is always debugging us with His debugger.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Perhaps std::list<std::wstring>?

  6. #6
    Registered User Moni's Avatar
    Join Date
    Oct 2002
    Location
    Dhaka, Bangladesh.
    Posts
    104
    yeah...but using STL...will be slower....I need faster....I'll go with the double pointer list ...with "malloc" "realloc" or "new"
    We all are the components of a huge program...... the programmer is always debugging us with His debugger.

  7. #7
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    STL isn't that slow.

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Using the STL will be faster.

  9. #9
    すまん Hikaru's Avatar
    Join Date
    Aug 2006
    Posts
    46
    Quote Originally Posted by Moni
    yeah...but using STL...will be slower....I need faster....
    How do you know it'll be slower? I read a lot, and just about everyone says that people worry too much about speed when they shouldn't. You should write programs that are correct and easy to understand. If it's not fast enough after that, then you can figure out where to make things faster. Unless you have performance statistics, it's impossible to know where bottlenecks will be.

  10. #10
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    >> ... I need faster ...

    I don't think you would notice the difference yourself! Why do you need it to be faster?

  11. #11
    The larch
    Join Date
    May 2006
    Posts
    3,573
    What makes you think STL is slow? It's most probably implemented by professionals who surely knew what they were doing.
    If it's slow, then the problem most probably is how you are using it...

  12. #12
    l2u
    l2u is offline
    Registered User
    Join Date
    May 2006
    Posts
    630
    How to make array with string? Like char** (pointer to pointer)

  13. #13
    すまん Hikaru's Avatar
    Join Date
    Aug 2006
    Posts
    46
    Quote Originally Posted by l2u
    How to make array with string? Like char** (pointer to pointer)
    With a vector.
    Code:
    std::vector<std::string> stringArray;

  14. #14
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    Look at the tutorial about vectors ... here - http://www.cprogramming.com/tutorial/stl/vector.html there are other tutorials too, just go to the tutorial index

  15. #15
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    > yeah...but using STL...will be slower....I need faster.
    You mean the 5 seconds it takes to use something already written and debugged compared to the days or weeks it would take you to roll your own.

    Not to mention the fact that you can't know for sure that this would even be a bottleneck in the final system.

    Look up "premature optimisation disease".

    Write it, get it working, then find out where the real hot spots are.
    Then write careful improvements which show useful performance improvements without breaking any tests.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Am I using *this properly?
    By Sebastiani in forum C++ Programming
    Replies: 3
    Last Post: 12-20-2001, 05:06 PM

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