To put it in more technical terms, allocate a buffer large enough to hold the data, then read the array index by index, use the length of each entry to determine the write offset in the buffer.......if the first string is "hello world" which is 12 characters long, you know the next write offset will be that +1 you may want to to store this offset in some variable to use it as your program reads your strings.
you can also combine an array of strings the following way.
string house("my house");
string dog("a big dog");
string car("fast car");
And I use getline() to get each line of a file into each element of that array.
Now I'm trying to combine them all into one string variable:
string sHack = "";
But when I try to use the append function it only appends the first element of the saHack array:
1 2 3 4 5
for (int i = 0;;i++)
{
if (saHack [i] == "DONE") break; // I use << endl << "DONE"; after I'm done writing to the file, this is just a check to see if we have reached the end of the string array.
sHack.append (saHack [i]);
}
Like I said before sHack only has the first element of saHack, and not all of it.
~~~~~NOTE:~~~~~
The text "DONE" is in element 479, not 1, so "DONE" is not the reason why it stops appending, if that is what some of you are thinking. I found this out by running this code:
1 2 3 4 5
int i;
for (i = 0;;i++) if (saHack [i] == "DONE") break;
char ca [50];
sprintf (ca, "%i", i);
MessageBox (NULL, ca, "", MB_OK);