I’m trying to write a code which stores strings in an array. I’m trying to do it with char* but I couldn’t achieve. I search the net but couldn’t find an answer. I’ve tried the code below, but it didn’t compile.I use string stream because at some point I need to concatenate a string with an integer.
stringstream asd;
asd<<"my name is"<<5;
string s = asd.str();
char *s1 = s;
Well, first you’ll need an arary of strings. I don’t like using naked arrays, so I use
std::vector:But, I understand you have to use an array, so we’ll use an array instead:
Okay, we’ll use stringstream:
That gets us one string, but you want an array of them:
Now you have an array of strings.
Complete, tested program: