"LPWSTR" 型別的值不能用於初始化 "char *" 型別的實體

老張謀發表於2017-10-09

"LPWSTR" 型別的值不能用於初始化 "char *" 型別的實體

void CFaceTemptureDlg::OnButtonClick_SO2()
{

	
	// TODO: Add your command handler code here 
	CString strLine, strTemp, result;
	int row = 0;
	CString filename = L"111.txt";
	CStdioFile file(L"111.txt", CFile::modeRead);

	while (file.ReadString(strLine))
	{
		char *str = strLine.GetBufferSetLength(strLine.GetLength());
		char *p;
		if (strLine != "")
		{
	                result += strLine;
			GetDlgItem(IDC_Edit_SO2)->SetWindowText(result);

			row++;
			
		}
	}
	file.Close();  }

解決辦法:   
型別轉換 參考知識  CString與LPCWSTR、LPSTR、char*、LPWSTR等型別的轉換

char *str = strLine.GetBufferSetLength(strLine.GetLength());
改為:

char *str = (char *)strLine.GetBufferSetLength(strLine.GetLength());


相關文章