在当前界面打开一个文本文档
- // open txt
- #include "stdio.h"
- #include "stdlib.h"
- int main()
- {
- system("start d:\\psnr.txt");
- return 0;
- }
- void CmfcopentxtDlg::OnBnClickedBopen()
- {
- // TODO: 在此添加控件通知处理程序代码
- ShellExecute(NULL, (LPCSTR)"open", (LPCSTR)"d:\\psnr.txt", NULL, NULL, SW_SHOWNORMAL);
- //父窗口句柄,动作,路径
- }
3、对文件数据的一些操作
- void CmfcreadtxtDlg::OnBnClickedBread()
- {
- // TODO: 在此添加控件通知处理程序代码
- FILE * fw = NULL;
- int k=0;
- char * str = new char[20];
- float d=0;
- float sum=0;
- //以附加方式打开可读文件
- fopen_s(&fw, "d:\\psnr.txt", "a+");
- if (!fw)
- {
- MessageBox("d:\\psnr.txt", "fail", MB_ICONWARNING);
- return;
- }
- while(!feof(fw))
- {
- k++;
- fscanf(fw, "%9s %f ", str, &d);
- sum += d;
- }
- sum = sum/k;
- fprintf(fw,"\n%s %f\n", "average", sum);
- k=0;
- sum=0;
- fclose(fw);
- fw = NULL;
- }