Don't use strcat
in C++ programs. It's a lot of work, and error-prone, since you have to do the memory management yourself.
If you just want to concatenate strings, use this:
std::string filename;
filename += "directory/";
filename += basename;
std::ofstream out(filename.c_str());
And if things get more complicated, use a std::ostringstream
, to which you can concatenate also integers and other objects.
In your special case, you created a C string "Encrypted/". This C string does not have room to append something. When you try anyway, you will overwrite arbitrary memory, leading to undefined behaviour. The assignment encf = edest
doesn't create a new string, it just makes encf
point to the same string as edest
.