如何用vc读取固定格式的文本
2008-11-02 12:55
423 查看
text1 123 456
text2 读取 固定
text3 0000 1111
想在程序中有四个Edit编辑框为
Edit1 、Edit2 、Edit3 、Edit4 、Edit5 、Edit6
和一个按钮button1
想让程序识别 text1、text2、text3后面的数字或文本
点击按钮button1
然后程序就会在
在Edit1中显示 123
在Edit2中显示 456
在Edit3中显示 读取
在Edit4中显示 固定
在Edit5中显示 0000
在Edit6中显示 1111
下面是高手jia_xiaoxin 的解答:
#include <fstream>
#include <string>
using namespace std;
void testdlg::GetFileText()
{
string str;
ifstream infile("C://out.txt");
if(!infile.is_open())//文件打开出错检查
{
AfxMessageBox("open file error!");
}
else
{
while(infile >> str)
{
if(str == "text1")
{
infile >> str;
SetDlgItemText(IDC_EDIT1, str.c_str());
infile >> str;
SetDlgItemText(IDC_EDIT2, str.c_str());
}
if(str == "text2")
{
infile >> str;
SetDlgItemText(IDC_EDIT3, str.c_str());
infile >> str;
SetDlgItemText(IDC_EDIT4, str.c_str());
}
if(str == "text3")
{
infile >> str;
SetDlgItemText(IDC_EDIT5, str.c_str());
infile >> str;
SetDlgItemText(IDC_EDIT6, str.c_str());
}
}
}
}
text2 读取 固定
text3 0000 1111
想在程序中有四个Edit编辑框为
Edit1 、Edit2 、Edit3 、Edit4 、Edit5 、Edit6
和一个按钮button1
想让程序识别 text1、text2、text3后面的数字或文本
点击按钮button1
然后程序就会在
在Edit1中显示 123
在Edit2中显示 456
在Edit3中显示 读取
在Edit4中显示 固定
在Edit5中显示 0000
在Edit6中显示 1111
下面是高手jia_xiaoxin 的解答:
#include <fstream>
#include <string>
using namespace std;
void testdlg::GetFileText()
{
string str;
ifstream infile("C://out.txt");
if(!infile.is_open())//文件打开出错检查
{
AfxMessageBox("open file error!");
}
else
{
while(infile >> str)
{
if(str == "text1")
{
infile >> str;
SetDlgItemText(IDC_EDIT1, str.c_str());
infile >> str;
SetDlgItemText(IDC_EDIT2, str.c_str());
}
if(str == "text2")
{
infile >> str;
SetDlgItemText(IDC_EDIT3, str.c_str());
infile >> str;
SetDlgItemText(IDC_EDIT4, str.c_str());
}
if(str == "text3")
{
infile >> str;
SetDlgItemText(IDC_EDIT5, str.c_str());
infile >> str;
SetDlgItemText(IDC_EDIT6, str.c_str());
}
}
}
}
相关文章推荐
- Flex中如何通过监听focusIn和focusOut事件,在通过displayAsPassword属性固定密码格式显示文本框获取焦点时显示文本
- vc 如何按格式显示文本内容
- C#读取固定文本格式的txt文件
- 如何让Hadoop读取以gz结尾的文本格式的文件
- 如何用VC从数据库中读取文本
- 如何让Hadoop读取以gz结尾的文本格式的文件
- 读取文本,匹配固定格式的字符串写入到另一个文件
- mid()——如何顺序读取单元格中的文本
- python2 和python3中分别如何读取文本
- VC对话框界面如何调整静态文本字体和大小?(转载)
- 在VC中如何将文件保存为EXCEL格式
- 在VC++应用程序中读取文本数据
- VC编程中如何设置对话框的背景颜色和静态文本颜色
- 【Vegas原创】导出Excel时,如何将数字格式转为文本格式?(07.12.13 Update)
- 用String分析固定格式的文本
- 如何读取DXF格式文件?
- matlab处理txt文本文件---数据格式要有规律性,否则要用编写特定方式进行读取
- C/C++中的输入与输出及如何读取一行文本
- 如何用VC读取Excel表格中的数据详细介绍
- python 4-3 如何调整字符串中文本格式re.sub(p,r'\1/\2',str1)/re.sub('(?P<Name>p),'\g<Name>',str1)