I've got this piece of code in C++ from someone else that I am now working with but I'm not sure why the "std::string()" is been added.
std::ifstream File;
std::stringstream FileName;
FileName << Name; //Name being a string that has been passed as an input to the function.
// Eg."MyFile"
newFileName << ".txt"; //"MyFile.txt"
File.open(std::string(FileName.str()).c_str(), std::ios::in | std::ios::binary);
My question is, since str() returns a string, and c_str() gets a string and transforms it into c string, why do we need to put it inside the "string()"? Could it not be writen like:
File.open((FileName.str()).c_str(), std::ios::in | std::ios::binary);