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());
- }
- }
- }
- }