Thread: Adding elements to a string

  1. #1
    Vicked
    Guest

    Adding elements to a string

    Hi

    This might be an easy question but I want to define one big long string or possibly alot of smaller strings, I want to be able to add elements to a string for example when someone clicks button1 it adds "action1 " to the string and when someone clicks button2 it adds "action2 " etc I also want to know how to ad line terminators to a string

    The aim is to output it all to a text file that is why I need line terminators, would it be easier to implement it as a string per line? I plan on having alot of lines, one big string might take up to much memory.

    I hope someone can help me

    Thanks

  2. #2
    eh ya hoser, got a beer? stumon's Avatar
    Join Date
    Feb 2003
    Posts
    323
    What do you have so far? Put some code so we may help you with something specific. If you dont have anything, read this first. CLICK ME
    The keyboard is the standard device used to cause computer errors!

  3. #3
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    You could keep your file open and write to it when necessary instead of keeping a lot of strings.

    In the other case you would use the dynamic memory allocation functions, like malloc, realloc and free to allocate memory for your string and resize the memory when the string needs to grow.

    You could also combine it. Store the text in a large string, if the string is full, write its contents to the file and then start storing at the beginning of the string again until it gets full again. It saves some file-writing actions. But it requires a more advanced memory management system.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  2. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. problems with overloaded '+' again
    By Brain Cell in forum C++ Programming
    Replies: 9
    Last Post: 04-14-2005, 05:13 PM
  5. "Operator must be a member function..." (Error)
    By Magos in forum C++ Programming
    Replies: 16
    Last Post: 10-28-2002, 02:54 PM