I have a function called "ExePath"
string exepath()
{
char buffer[MAX_PATH];
GetModuleFileName( NULL, buffer, MAX_PATH );
return std::string(buffer);
}
This returns the path of the application. Later, I try to copy the application to another place.
CopyFile(exepath, "C:\\Example\\Example.exe", FALSE);
When compiling I get the following error:
[Error] cannot convert 'std::string' to 'LPCSTR' for argument '1' to 'WINBOOL CopyFileA(LPCSTR, LPCSTR, WINBOOL)'
I take this as it cant use the string as a string. What? Basically I am trying to find the path that the application has been executed and copy it to another place. Any and all help is appreciated.
std::stringandLPCSTRare two completely different types. The compiler's error message couldn't be more clear. You should spend some time studying the difference betweenstd::string, a C++ class, and C-style strings, and how to convert between the two.exepathneeds to be called asexepath.c_str()