Thread: std::string length

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    128

    std::string length

    Does string have an unlimited length?

    I'll be parsing text files and need the whole file to fit into a string.

    And regarding that,
    would it be faster to parse the whole file for certain words
    or
    would it be faster to remove words of less than 4 letters and then parse the smaller string?

    And now that i'm getting used to vectors, would it be better/faster to break up the file words into a vectored list and then parse the vector list?

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Quote Originally Posted by FoodDude
    Does string have an unlimited length?
    No, the max_size() member function will return a value indicating the maximum number of characters that a string may contain.
    "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

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    The best way to read and parse depends on the data you have and your speed/memory requirements. If there are obvious breaks in the data (e.g. newlines, commas, or some other delimiter) then breaking it up might be easier.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Does string have an unlimited length?
    No, but if you use it intelligently, you'll probably never reach the maximum length.

    >I'll be parsing text files and need the whole file to fit into a string.
    Why? Is it not possible to parse the file in increments? Is it not possible to break the file up into multiple files? Reading the whole file into fast memory is a naive solution that isn't always viable.
    My best code is written with the delete key.

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    128
    thanks to all.

    I found a way to read it in, one line at a time and pop distinct words into a vector. In time, the file might just be a stream of data coming in, so I'll have to deal with that when the time comes.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Strange string behavior
    By jcafaro10 in forum C Programming
    Replies: 2
    Last Post: 04-07-2009, 07:38 PM
  3. Replies: 13
    Last Post: 12-14-2007, 03:34 PM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. Debugging help
    By cuddlez.ini in forum C++ Programming
    Replies: 3
    Last Post: 10-24-2004, 07:08 PM