zoukankan      html  css  js  c++  java
  • vc 添加打开文件对话框并读取文件

     1.创建打开文件对话框:  
                                    CFileDialog dlg(TRUE,//TRUE是创建打开文件对话框,FALSE则创建的是保存文件对话框
                                     ".txt",//默认的打开文件的类型
                                     NULL,//默认打开的文件名
                                     OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,//打开只读文件
                                    "文本文件(*.txt)|*.txt|所有文件 (*.*)|*.*||");//所有可以打开的文件类型
    2.点打开文件对话框上面的确定键后
                                                    if(dlg.DoModal()==IDOK)  
                                                     {
                                                      CString m_FilePath = dlg.GetPathName();////////取出文件路径
                                                      CString  m_path;
                                                     m_path=m_FilePath;//将文件的路径放入m_path
                                                     UpdateData(FALSE);
                                                     }
    3.打开文件:File.Open(m_path,CFile::modeRead);
    4.逐行读取文件:CStdioFile File;///可以逐行读文件的类
                             CString   strLine;    
                             while(File.ReadString(strLine))   //////将每行都放进strLine字符串里
                             {    
                              AfxMessgeBox(strLine);
                             }  
    5判断读出来的字:
                              strLine=“1|2|3|”;//要判断的字符串
                              int strIndex1  = strLine.Find('|');//在字符串中寻找“|”
                              CString a[11];
                              if(-1 != strIndex1)//只要找到“|”就不会返回-1
                              {
                               int i=0;
                                   while(  -1 != strIndex1)//
                                   {    
                                       strIndex1 = strLine.Find('|');
                                       a[i] = strLine.Left(strIndex1);
                                      strLine = strLine.Right(strLine.GetLength() - strIndex1-1) ;
                                       i++;
                                      if (i > 10)//退出循环
                                      break;
                                     }
                           }


    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/halibobo520/archive/2008/11/25/3371944.aspx

  • 相关阅读:
    shell 命名管道,进程间通信
    bash shell:重定向标准错误输出
    paramiko socket.error: Int or String expected
    django csrf_token生成
    shell基础知识
    复制vi全部内容到windows ctrl+shift+c
    linux配置bridge (不同网段)
    sdk shell下脚本.soc
    X86服务器BMC基板管理控制器介绍
    linux 开启vnc
  • 原文地址:https://www.cnblogs.com/joeblackzqq/p/1910898.html
Copyright © 2011-2022 走看看