您的位置:首页 > 其它

CStdioFile Class

2015-12-06 23:37 134 查看

CStdioFile : CFile : CObject

A CStdioFile object represents a C run-time stream file as opened by the run-time functionfopen. Stream files are buffered and can be opened in either text mode (the default) or binary mode.

Text mode provides special processing for carriage return–linefeed pairs. When you write a newline character (0x0A) to a text-modeCStdioFile object, the byte pair (0x0D, 0x0A) is sent to the file. When you read, the byte pair (0x0A, 0x0D)
is translated to a single 0x0A byte.

The CFile functions
Duplicate, LockRange, and
UnlockRange are not supported for CStdioFile.

If you call these functions on a CStdioFile, you will get a
CNotSupportedException.

For more information on using CStdioFile, see the articleFiles in MFC inVisual C++ Programmer’s Guide andFile Handling in the
Run-Time Library Reference.

#include <afx.h>

CStdioFile Class Members

Data Members
m_pStreamContains a pointer to an open file.
Construction
CStdioFileConstructs a CStdioFile object from a path or file pointer.
Text Read/Write
ReadStringReads a single line of text.
WriteStringWrites a single line of text.
eg:     
CString strPath = "F:\\VBA\\*.*";
CString strFileName;

CStringArray strResult;
strResult.RemoveAll(); //文件列表清空

CFileFind finder;

CStdioFile OutFile;
BOOL bWorking = finder.FindFile(strPath);
while (bWorking)
{
bWorking = finder.FindNextFile();
if(finder.IsDirectory()) //若确定找到的文件是否是一个目录,结束本次循环。
continue;
strFileName = finder.GetFileName();
//cout << (LPCTSTR)strFileName << endl;
strResult.Add(strFileName);
}
finder.Close();
int iCount = strResult.GetSize();
if(iCount > 0)
{
//OutFile.Open("F:\\VBA\\Names.xls",CFile::modeCreate | CFile::modeWrite);
OutFile.Open("F:\\VBA\\Names.txt",CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite);
int i;
for(i = 0;i < iCount;i++)
{
cout << (LPCTSTR)strResult.GetAt(i) << "\n";
OutFile.WriteString(strResult.GetAt(i) + "\n");
}
cout << "最大索引是:" << strResult.GetUpperBound() << "\n";
cout << "元素总数是:" << strResult.GetSize() << "\n";
OutFile.Close();
system("pause");
}
else
{
;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: