arrays - C++: Storing strings in linked list -
(i've used c++ recreationally, forgive noobish question.)
i want write simple spreadsheet program works in terminal (via ncurses). personal edification. want store cells linked lists wouldn't have reallocate bunch of data every time wanted move or insert rows; each cell node in linked list, contains cell's data. data consist of ascii characters.
relevant consideration: naturally, of these cells have resized accommodate more characters.
question: datatype should use store cell contents?
thoughts: i've never used std::string , kinda skeptical of idea after rather sour experience trying program in d :). i'm open possibility they're not bad. thinking of using char arrays[], fit bill pretty nicely , consistent c intuition. stumbled upon suggestion use std::vector while looking through stackoverflow, seems better since they're easy resize, fear might considered clumsy.
g'day , thankee much.
if storing "string", std::string
starting point. these allow resizing , take little more space char *
[which you'd have use if want resize string - , want load file has lines longer x - no matter x is, right?]. in fact, in typical implementation there's 2 size_t
variables above , beyond pointer, , that's it. , need @ least 1 of them go along char *
anyway keep track of length of actual string , size of memory have allocated string - since don't want calling new
, strcpy
, delete
every single time string changes size - unless real masochist. (being little bit masochistic fine, that's part of being software developer - if little pain stops you, give before achieve anything)
in text editor, inserting, splitting , removing parts of string, having functions available in std::string
class. "keeping track of memory you".
Comments
Post a Comment