VC Add Open File dialog box and read file

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/halibobo520/article/details/3371944

1. Create open File dialog box:
CFileDialog Dlg (True,//true is the Create Open File dialog box, False creates a Save File dialog box
". txt",//the type of the default open file
null,//The file name that is opened by default
Ofn_hidereadonly | ofn_overwriteprompt,//opening a read-only file
"text file (*.txt) |*.txt| All Files (*. *) |*.*| |"); /all file types that can be opened
2. Click OK after opening the file dialog box
if (dlg. DoModal () ==idok)
                                                 { 
CString M_filepath = dlg. GetPathName ();////////Remove file path
CString M_path;
m_path=m_filepath;//The path of the file into M_path
UpdateData (FALSE);
                                                 } 
3. Open file:file.open (m_path,cfile::moderead);
4. Progressive reading of files : CStdioFile file;///classes that can read a file line-by-row
CString StrLine;
While (File.readstring (strLine))//////puts each line in the StrLine string
                         {     
Afxmessgebox (strLine);
                         }   
5 Judging the words read out:
strline= "1|2|3|"; /The string to be judged
int strIndex1 = strline.find (' | '); /find "|" in the string
CString a[11];
if ( -1! = strIndex1)//Just find "|" Will not return-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)//exit cycle
Break ;
                                 } 
                       } 

VC Add Open File dialog box and read file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.