limitations and practicality of string in c++ stl

This is a discussion on limitations and practicality of string in c++ stl within the C++ Programming forums, part of the General Programming Boards category; Okay, for a program that I am writing I am using xml documents as a means of desiding on the ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    110

    limitations and practicality of string in c++ stl

    Okay, for a program that I am writing I am using xml documents as a means of desiding on the layout and content of objects on screen.

    Now as each xml document will undoutably contain text to display (not talking about the entire document) inside of a <writing> ... </writing> tag set I need an easy and fast way to access this data.

    One obvious option is to place the text inside of a single string data type, though with the text being in the vacinity of a couple of thousand words (theoreticaly needed to be infinate capacity) this just seems impractical.

    Another suggestions would be to have a linked list / stack / queue of strings each roughly 200 words long.

    What I wan't to know is what are the imaganitive solutions that people have come up with / aware of to overcome this problem.

    Later,
    WebmasterMattD
    http://www.webmastermattd.net

  2. #2
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Is the string going to be modified or changed? That is, do you plan to concatenate to it, etc?

    If you are going to change the strings relatively rarely, then using one string is the best approach. It uses the least memory (as, after all, you always need to allocate enough memory to hold the data).

    If you are going to do a lot of modifications, then you probably want the equivalent of a linked list of string segments; I'd break into characters, not words, though.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    That is exactly what this does. Tokens are assembled into a list<pair<int,string>>.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    110
    Essentially the string could well be defined as a constant. What I eventually want to do is place a different section of the text on screen at a particular time (GUI app) and have a scroll box type arrangement. I am using a combination of SDL and OpenGL to work with the string.

    Does this change the mannor in which I should approach the problem (have never done anything on this scale before as far as workint with strings is concerned.)

    Later,
    WebmasterMattD
    WebmasterMattD.NET

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Well, as far as the organization of the tagged data, xml requires something roughly equivalent to a linked lists of linked lists. Each list serves both as an element and a parent to zero or more child elements.

    If you want to experiment with parsing the xml, the scanner object I posted a link to comes with an example C++ parser (incomplete).
    Last edited by Sebastiani; 10-06-2003 at 07:09 AM.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  6. #6
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Originally posted by WebmasterMattD
    Essentially the string could well be defined as a constant. What I eventually want to do is place a different section of the text on screen at a particular time (GUI app) and have a scroll box type arrangement. I am using a combination of SDL and OpenGL to work with the string.

    Does this change the mannor in which I should approach the problem (have never done anything on this scale before as far as workint with strings is concerned.)

    Later,
    If the string will be a constant, then I recommend one single STL string. There should be no upper size limit on the string, and if you're not changing it, then you don't have to worry about expensive copy operations.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

Popular pages Recent additions subscribe to a feed

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