The dot operator does not concatenate strings as you seem to think it does. If you have string objects (as in, std::string), you can concatenate strings with the + operator. Otherwise, if you have a char array, you can use the strcat function.
Assuming Stat.subFolder is a string and not a char array, you can do it like this:
1 2
|
S::I().Stat.subFolder = S::I().Stat.workingPath;
S::I().Stat.subFolder += "\\" + *it;
|
The reason for the two-step assignment here is because you cannot use + to join char arrays -- at least one of them must be a string object. Both "\\" and workingPath are char arrays, so they cannot be joined with +. So that's why I assign workingPath to subFolder (assuming subFolder is a string) first.
The second line I can use + to join "\\" and *it because *it is a string object.
* Note you could do this in one line by constructing a string object from workingPath or "\\":
|
S::I().State.subFolder = S::I().Stat.workingPath + string("\\") + *it;
|
If subFolder is
not a string... if it is a char array... then blech... .stop using char arrays. Anyway, if that's the case, then you can do this:
1 2 3
|
strcpy( S::I().Stat.subFolder, S::I().Stat.workingPath );
strcat( S::I().Stat.subFolder, "\\" );
strcat( S::I().Stat.subFolder, it->c_str() );
|
As you can see, this becomes a 3 step problem as each portion of the string must be appended individually
* technically this is not true, you could cram all of this into one line by nesting all these calls within each other, but it is ugly and confusing:
1 2
|
// I think I did this right...
strcat( strcat( strcpy( S::I().Stat.subFolder, S::I().Stat.workingPath ), "\\"), it->c_str() );
|
Ideally... everything here would be a string object. Then we could just do this:
|
S::I().Stat.subFolder = S::I().Stat.workingPath + "\\" + *it;
|
So let that be the moral to this story: favor strings over char arrays.