The +
operator does not do string concatenation with two string literals. In C++ (going by your tags), you can use std::string
to do the concatenation:
#include <string>
...
std::string baseFilename("abc");
std::string newFilename(baseFilename + ".txt");
freopen(newFilename.c_str(), "w", file);
The std::string
class does support concatenation via +
. Note that we're using c_str()
because the freopen()
function still takes a C-style string pointer (const char *
).