VC add open file dialog box and Read File

Source: Internet
Author: User

1. Create an open file dialog box:
Cfiledialog DLG (true, // true indicates the create open file dialog box, and false indicates the save file dialog box.
". Txt", // The default file type to open
Null, // default open file name
Ofn_hidereadonly | ofn_overwriteprompt, // open the read-only file
"Text file (*. txt) | *. txt | all files (*. *) | *. * |"); // all types of files that can be opened
2. Click the OK button in the open file dialog box.
If (DLG. domodal () = idok)
{
Cstring m_filepath = DLG. getpathname (); //// // retrieve the file path
Cstring m_path;
M_path = m_filepath; // put the file path into m_path
Updatedata (false );
}
3. open the file: file. Open (m_path, cfile: moderead );
4. Read files row-by-row: cstdiofile file; // class of files that can be read row-by-row
Cstring strline;
While (file. readstring (strline) ///// put each row into the strline string
{
Afxmessgebox (strline );
}
5. Judge the words read:
Strline = "1 | 2 | 3 |"; // string to be judged
Int strindex1 = strline. Find ('|'); // search for "|" in the string"
Cstring A [11];
If (-1! = Strindex1) // If "|" is found,-1 is not returned.
{
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 the loop
Break;
}
}

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/halibobo520/archive/2008/11/25/3371944.aspx

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.