So I am trying to move a file that the user specifies by using cin and MoveFile(). But the thing is MoveFile() parameters take LPCTSTR variables but cin doesnt take those variable types can anyone help me with a conversion from a char myChars[] table to a LPCTSTR variable?
Many Microsoft functions come in different flavours depending on the type of characters which are in use.
In order to use a plain C++ character array, use the MoveFileA() variant. This is the same as MoveFile() but operates on ordinary char rather than T‌CHAR.
MoveFileA (and MoveFileW, for that matter) returns a BOOL already, so CopyThisFile is using the wrong return type for the function (and will get a signed/unsigned warning when compiled if you are being good and have cramked up your warning level.)
Also, as I like things to be consistent, you should really use true and false with the C++ bool type, not the archaic typedef (of int) BOOL (which goes with the hash #defines TRUE and FALSE).
1 2 3 4 5 6 7 8 9 10
bool CopyTheFile()
{
BOOL result = MoveFileA("C:\\Users\\username\\Desktop\\test.exe",
"C:\\Users\\username\\Desktop\\folder1\\test.exe");
if (!result)
{
returnfalse;
}
returntrue;
}