Create a console window in MFC

Insert code in stdafx.h

#pragma comment(linker, "/entry:WinMainCRTStartup /subsystem:console")

The print result is output.

string to LPCTSTR

Very simple way~

string s;
CString cs(s.c_str()); //< - lpctstr


Set up VisualStudio to run programs as an administrator

Enter the project properties and change the Configuration Properties -> Linker -> Manifest File -> UAC Execution Level item to requireAdministrator.