RSS Forums RSS
Please support our C++ advertiser: Programming Forums

Declaring string array, initializing later...

Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,861
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 40
Solved Threads: 1012
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Declaring string array, initializing later...

  #7  
May 25th, 2006
>>I like this one but I want to avoid declaring all strings at once and then choosing (honestly I might have dozens of 20-entry arrays, I'm not sure how many arrays I will need yet).

If all the strings are hard-coded in the program, they take up the same amount of memory wherever you put them. The compiler will put all those strings into some (probably) read-only memory block, so your concern is a non-issue. Probably a better solution is to put the strings in a text file then read them into memory at runtime. you can create a text file similar to standard ini file
// strings.txt
[entry-1]
Entry 1
Entry 2
...
Entry n
[entry-2]
Entry A
Entry B
...
[entry-n]
...
your program will look for the tag it needs then read the strings until ene-of-file or another tag name is encountered. This method gives you a lot more flexibility because you can freely add more strings to the text file and not worry about adding/recompiling your program.
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 11:04 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC