Thread: Infinite array size???

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    417

    Question Infinite array size???

    I have a text file, say it is text.txt, and I want to put it in an array, but I don't want there to be a limit on the array's size. I want it to be able to handle insanely large number of characters in a string, and then overwrite the text with the output.

  2. #2
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    Then you want the STL.

    A vector<string> is effectively a boundless array of boundless arrays of characters.

    If you want them to be indexed by keywords, then a map<string, string> would be more effective.

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    You can use vector or create a class that loops and creates new variables with each input using new keyword. Vectors may be easier though.
    C++ Rules!!!!
    ------------
    Microsoft Visual Studio .NET Enterprise

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    417
    1) Does a "vector" work like a string (same commands...)

    2) How do I declare a vector/ use it?

    Thanks!

  5. #5
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    No, it works much less like a string and rather more like a vector.

    You can find a bit of info here. (And yes I looked over this one first to make sure the info was at least semi legit)

  6. #6
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072

    Re: Infinite array size???

    Originally posted by Trauts
    I want it to be able to handle insanely large number of characters in a string, and then overwrite the text with the output.
    Perhaps you should consider to only read portions of the file at one time, process it and then read some more.

    If you really mean insanely large, remember that most implementations of fstream has a 2-4 GB file size limit (actually this has caused me some trouble) and you can never allocate more than 4 GB memory on a windows system (Win32, that is, win64 is not very common).
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  7. #7
    Registered User
    Join Date
    Sep 2002
    Posts
    417
    an insanely large number of characters... not of file size.

    I'll just do part of a file at a time... no point in learning that before I'm ready
    Last edited by Trauts; 11-03-2002 at 04:45 PM.

  8. #8
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    most implementations of fstream has a 2-4 GB file size limit
    I'm confused... I made a program that created a 27 gb text file... what am I missing?
    Just Google It. √

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

  9. #9
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by Hunter2
    I'm confused... I made a program that created a 27 gb text file... what am I missing?
    nothing, your implemenation does not have this limit.
    hello, internet!

  10. #10
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    ... okay, sounds good
    Just Google It. √

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

  11. #11
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Originally posted by Hunter2
    I'm confused... I made a program that created a 27 gb text file... what am I missing?
    Did you use Windows API functions? The API functions are always capable of creating large files.

    But most (some?) implementations of the standard library uses a 32-bit integer to store the filesize. Naturally, problems occur when opening a file larger than 4GB.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  12. #12
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Well, I used a std:fstream and used a for loop, each iteration writing another character to the file... is that Windows API?
    Just Google It. √

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

  13. #13
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    no
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  14. #14
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    What? No analysis of why it worked based on my response?
    Just Google It. √

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

  15. #15
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    >But most (some?) implementations of the standard library uses a 32-bit integer to store the filesize

    I currently use API specific functions to handle files. However, I am thinking about re-writing large parts of my code to make it non-OS specific & portable. I need to access large files (i.e. size > 4GB).

    Are you saying that standard C++ methods do not allow for files > 4GB on a 32 bit OS?
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. size of array
    By goran00 in forum C Programming
    Replies: 38
    Last Post: 04-02-2008, 09:57 AM
  2. Little Array Difficulty
    By G4B3 in forum C Programming
    Replies: 16
    Last Post: 03-19-2008, 12:59 AM
  3. Array size
    By tigrfire in forum C Programming
    Replies: 5
    Last Post: 11-14-2005, 08:45 PM
  4. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 01:01 AM