刚学c++的小白,在网上看到一段读写ini文件的代码,想试试结果有错。

#include "stdafx.h"
#include
#include
#include
using namespace std;
int main()
{
LPTSTR lpPath= new char[MAX_PATH];

strcpy(lpPath, "D:\\IniFileName.ini");

WritePrivateProfileString("LiMing", "Sex", "Man", lpPath);
WritePrivateProfileString("LiMing", "Age", "20", lpPath);

WritePrivateProfileString("Fangfang", "Sex", "Woman", lpPath);
WritePrivateProfileString("Fangfang", "Age", "21", lpPath);

delete[] lpPath;
system("pause");

}
报错为:“char *” 类型的值不能用于初始化“LPTSR”类型的实体;

以下代码即可

 LPTSTR lpPath= LPTSTR(new char[MAX_PATH]);