⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filesrch.cpp

📁 API经典入门
💻 CPP
字号:
// Filename: filesrch.cpp    

#include "stdafx.h"

BOOL Search (const char* lpszFilename, const char* pSubString,
			WORD wStringLen, LONG& lFoundAt, LONG lStartAt = 0)
{
	CFile fileToSearch;
	CFileException e1;
	
	if ( !fileToSearch.Open(lpszFilename,
		 CFile::modeRead, &e1 ) )
	{
		// if Open() fails, pass the problem
		// to the caller.
		THROW(&e1);
	}

	TRY
	{
		// Seek to the starting position.
		fileToSearch.Seek(lStartAt, CFile::begin);
	}
	CATCH(CException, e2)
	{
		// If lStartAt isn't a legitimate position
		// then our search finds nothing!
		fileToSearch.Close();
		return FALSE;
	}
	END_CATCH

	DWORD dwFilePos = fileToSearch.GetPosition();
	WORD wStringPos = 0;
	BOOL Found = FALSE;
	BYTE b;

	// Start searching through the file.
	TRY
	{
	while (fileToSearch.Read(&b, 1) == 1)
	{
		if (b == pSubString[wStringPos])
		{
			wStringPos++;
			if (wStringPos == wStringLen)
				Found = TRUE;
			continue;
		}
		if (wStringPos > 0)
			fileToSearch.Seek(dwFilePos, CFile::begin);
		wStringPos = 0;
		dwFilePos++;		
	}
    }
    CATCH(CException, e)
    {
    	TRACE0("Search failed.\n");
    }
    END_CATCH
    
	fileToSearch.Close();

	return Found;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -