And is there not a case to be made for using char* instead, in terms of time-wise performance? |
"Premature Optimization is the root of all evil" - Donald Knuth
"The greatest optimization is going from 'not working' to 'working.'" - Ron Hiller
"If correctness doesn't matter then a program can be optimized to an arbitrary degree." - Chris Macey
Okay, I'm sure nobody here has heard of my former coworkers Ron and Chris, but their words are still very valid.
Is there a case to use char* to improve performance? Mmmmmmmaybe... If all else has failed. It will also reduce the memory footprint slightly, but it might actually harm performance. In both cases, that's because std::string stores the size of the string. Do you have a measured performance problem in this code? Are you certain that you need to fix it? Can you improve the performance of some other code instead?
Your readFile() function doesn't appear to leak memory to me, but it does leak the FILE pointer. You need to add fclose(pFile).
Can you use char* as the values in a vector like you have? I suppose so, as long as you keep it crystal clear who owns the char*. For example, don't make a copy of that vector.
Can you use char* as the key in a map? I suspect not, or at least not without difficulty. Before destroying the map, you'd have to remove each item and delete the key
after removing it.
So in both of these cases, I'd just use std::string. Doing it with char* will result in fragile code - code that can easily break if someone makes a change to it.