Hi,
I'd like to know, given a string how do i find it in a set of files.
For example I have to find a string "CServer" in a set of .cpp files.
How do I implement this in my application?
Thanks in advance
Printable View
Hi,
I'd like to know, given a string how do i find it in a set of files.
For example I have to find a string "CServer" in a set of .cpp files.
How do I implement this in my application?
Thanks in advance
you can open each file in your file spec using CStdioFile and scan it using CStdioFile's ReadString method.
Then scan each line using CString's Find method.
try that:
with CFile.Read get your file in a CString-buffer and then go ahead as follows...
int Find( LPCTSTR lpszSub ) const;
Return Value
The zero-based index of the first character in this CString object that matches the requested substring or characters; –1 if the substring or character is not found.
Parameters
ch A single character to search for.
lpszSub A substring to search for.
Remarks
Searches this string for the first match of a substring. The function is overloaded to accept both single characters (similar to the run-time function strchr) and strings (similar to strstr).
Example
The following example demonstrates the use of CString::Find.
// example for CString::Find
CString s( "abcdef" );
ASSERT( s.Find( 'c' ) == 2 );
ASSERT( s.Find( "de" ) == 3 );
No actually I was looking for a class like CFindFile. Is this the only method I can do it?
there is CFileFind class in MFC (not CFindFile).
is this the only method, you ask?
There is never ever only ONE method in programming :-)