str.Format(L"%d ",m_iHCount); hotel+=str;
时间: 2024-05-30 17:09:56 浏览: 10
这段代码是将整型变量 m_iHCount 转换成字符串格式,并且加到字符串变量 hotel 的末尾。具体来说,str 是一个 CString 类型的变量,调用其 Format 方法将整型变量 m_iHCount 格式化成字符串,并且加上一个空格。然后将格式化后的字符串加到字符串变量 hotel 的末尾。最终 hotel 变量保存的是一个字符串,其末尾包含了 m_iHCount 的值和一个空格。
相关问题
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(); }为什么信息显示不出来
根据你提供的代码,我无法准确判断信息为何无法显示出来。但从代码中可以看出,你将酒店信息写入了一个名为 "hotel.txt" 的文件中,因此可能是读取文件时出现了问题。
你可以尝试检查以下几个方面:
1. 确认文件是否存在,是否有写入权限。
2. 在写入文件之后,尝试读取文件,看看文件中是否真的有写入的信息。
3. 检查程序中读取文件的代码是否正确,包括文件路径、文件打开方式等。
如果以上都没有问题,你可以提供更详细的信息和代码,以便更好地帮助你解决问题。
#!/usr/bin/python3 stopword = '' stri = '' try: for line in iter(input, stopword): stri += line + '\n' except EOFError: pass stri = stri[0:-1] # do something... int1_count = 0 str_count = 0 other_count = 0 kong_count = 0 for i in stri: if i.isdigit(): int1_count += 1 elif i.isalnum(): str_count += 1 elif i == ' ': kong_count += 1 else: other_count += 1 print('%d spaces, %d numbers, %d letters, %d other characters.' %(kong_count, int1_count ,str_count,other_count))注释一下
这是一个Python脚本,主要功能是统计用户输入的字符串中包含的空格、数字、字母和其他字符的数量,并输出统计结果。以下是代码注释:
```python
#!/usr/bin/python3 # 声明解释器类型为Python3
stopword = '' # 停止输入的标志字符串
stri = '' # 存储用户输入的字符串
try: # 开始输入循环,直到遇到停止符为止
for line in iter(input, stopword):
stri += line + '\n'
except EOFError: # 如果输入结束,则跳过输入循环
pass
stri = stri[0:-1] # 去掉字符串末尾的换行符
# 统计空格、数字、字母和其他字符的数量
int1_count = 0 # 记录数字的数量
str_count = 0 # 记录字母的数量
other_count = 0 # 记录其他字符的数量
kong_count = 0 # 记录空格的数量
for i in stri:
if i.isdigit(): # 如果是数字,则数字数量加1
int1_count += 1
elif i.isalnum(): # 如果是字母,则字母数量加1
str_count += 1
elif i == ' ': # 如果是空格,则空格数量加1
kong_count += 1
else: # 否则是其他字符,则其他字符数量加1
other_count += 1
# 输出统计结果
print('%d spaces, %d numbers, %d letters, %d other characters.' %(kong_count, int1_count ,str_count,other_count))
```
在脚本中,我们使用`try...except`语句来实现输入循环,通过`iter()`函数来实现每次输入一行,并将输入的字符串拼接到`stri`变量中。然后,我们使用`isdigit()`和`isalnum()`方法来判断字符是数字还是字母,如果是空格则直接判断,其他字符则使用`else`语句进行判断。最后,我们使用`print()`函数输出统计结果。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)