CString hotel; CString str; hotel+=m_strHId; hotel+=' '; hotel += m_strHName; hotel += ' '; hotel += m_strHCity; hotel += ' '; wchar_t *wText=CStringToWChar(m_strHName); DWORD dwNum = WideCharToMultiByte(CP_OEMCP,NULL,wText,-1,NULL,0,NULL,FALSE); char *psText; psText = new char[dwNum]; WideCharToMultiByte (CP_OEMCP,NULL,wText,-1,psText,dwNum,NULL,FALSE); hotel+=psText; hotel+=' '; wText=CStringToWChar(m_strHCity); dwNum = WideCharToMultiByte(CP_OEMCP,NULL,wText,-1,NULL,0,NULL,FALSE); psText = new char[dwNum]; WideCharToMultiByte (CP_OEMCP,NULL,wText,-1,psText,dwNum,NULL,FALSE); hotel+=psText; hotel+=' '; str.Format(L"%d ",m_iHCount); hotel+=str; str.Format(L"%d ",m_iComCount); hotel+=str; str.Format(L"%d ",m_iComEmpCount); hotel+=str; str.Format(L"%d ",m_iComPrice); hotel+=str; str.Format(L"%d ",m_iSupCount); hotel+=str; str.Format(L"%d ",m_iSupEmpCount); hotel+=str; str.Format(L"%d\n",m_iSupPrice); hotel+=str; delete [] wText; delete [] psText; CStdioFile file; file.Open(_T("hotel.txt"),CFile::modeCreate|CFile::modeNoTruncate||CFile::modeWrite); file.SeekToEnd(); file.WriteString(hotel); file.Close(); MessageBox(L"酒店信息添加成功!",L"提示"); CDialogEx::OnOK(); } } void CAddHotelDlg::OnBnClickedCancel() { CDialogEx::OnCancel(); }为什么信息显示不出来
时间: 2024-01-10 22:04:56 浏览: 243
根据你提供的代码,我无法准确判断信息为何无法显示出来。但从代码中可以看出,你将酒店信息写入了一个名为 "hotel.txt" 的文件中,因此可能是读取文件时出现了问题。
你可以尝试检查以下几个方面:
1. 确认文件是否存在,是否有写入权限。
2. 在写入文件之后,尝试读取文件,看看文件中是否真的有写入的信息。
3. 检查程序中读取文件的代码是否正确,包括文件路径、文件打开方式等。
如果以上都没有问题,你可以提供更详细的信息和代码,以便更好地帮助你解决问题。
相关问题
wchar_t *wText=CStringToWChar(m_strHName); DWORD dwNum = WideCharToMultiByte(CP_OEMCP,NULL,wText,-1,NULL,0,NULL,FALSE); char *psText; psText = new char[dwNum]; WideCharToMultiByte (CP_OEMCP,NULL,wText,-1,psText,dwNum,NULL,FALSE); hotel+=psText; hotel+=' '; wText=CStringToWChar(m_strHCity); dwNum = WideCharToMultiByte(CP_OEMCP,NULL,wText,-1,NULL,0,NULL,FALSE); psText = new char[dwNum]; WideCharToMultiByte (CP_OEMCP,NULL,wText,-1,psText,dwNum,NULL,FALSE); hotel+=psText; hotel+=' ';
这段代码是将 CString 类型的 m_strHName 和 m_strHCity 转换为 char 类型的 hotel 字符串,并在它们中间添加一个空格。这里使用了 WideCharToMultiByte 函数将 Unicode 编码的字符串转换为 ANSI 编码的字符串,以便后续处理。同时,也需要注意在代码结尾处使用了 new 关键字动态分配内存,需要在适当的时候使用 delete 关键字释放内存。
str.Format(L"%d ",m_iHCount); hotel+=str;
这段代码是将整型变量 m_iHCount 转换成字符串格式,并且加到字符串变量 hotel 的末尾。具体来说,str 是一个 CString 类型的变量,调用其 Format 方法将整型变量 m_iHCount 格式化成字符串,并且加上一个空格。然后将格式化后的字符串加到字符串变量 hotel 的末尾。最终 hotel 变量保存的是一个字符串,其末尾包含了 m_iHCount 的值和一个空格。
阅读全文
相关推荐

















