The very first line in your code snippet (std::string finalStr;
) declares the finalStr
variable.
Then, within the else
part you're declaring another variable named finalStr
which is local to that scope (the opening brace after the else
to its matching closing brace). This variable now hides the first one, and references to finalStr
within this scope, after the declaration, will refer to the local variable, not the finalStr
declared in the enclosing scope.
To fix the problem, do not re-declare the variable, just assign finalStr
a new value.
std::strcpy(curLine, bstrInputString.operator char *());
finalStr = curLine;
// ^^^^^
// assign new value instead of creating another variable with the same name