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