CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: String in c++

  1. #1
    Join Date
    Mar 2010
    Posts
    13

    String in c++

    I was storing a lot of things into my string, and it seems to have run out of memory. I have thought about using a array/vector of characters, however, I wish to retain the ability to do substring, and to read from a file into it. It is possible to read from a file into an array of characters (as in is there a method to do it?). If not, is there some sort of data storage that won't run out of memory, or dynamically changes size? (I hope that made sense. In short, I am running out of memory in my string and want an alternative)

    Thanks in advance

  2. #2
    Join Date
    Aug 2009
    Location
    Romania->Felnac
    Posts
    48

    Re: String in c++

    I think you are looking for std::string, here is a simple tutorial:
    http://www.codeguru.com/cpp/cpp/stri...cle.php/c13267

  3. #3
    Join Date
    Mar 2010
    Posts
    13

    Re: String in c++

    Is it possible to increase the max size of a string?

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: String in c++

    A std::string's size is limited only by available memory. Unless you have a string over a billion characters long, that isn't your trouble.

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: String in c++

    What makes you think you're running out of memory in your string?

  6. #6
    Join Date
    Jan 2009
    Posts
    1,689

    Re: String in c++

    If you have a string that's taking over 4GB of RAM, then I would rethink your program design. I can think of very few reasons that you would require a string that big, and if you are unfamiliar with std::string, I don't think that you're using it for one of those reasons.

  7. #7
    Join Date
    Mar 2010
    Posts
    11

    Re: String in c++

    If you are using big text files (or where else do you use such a big string?) then it is better to read them by small parts or start using file mapping.

    You never know how big a file may be, so try to always work with parts of a file, not the whole.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured