printf( "+[%s]\n" (LPCSTR)strName ); ?有关问题见27 28行注释

printf( "+[%s]\n", (LPCSTR)strName ); ??????问题见27 28行注释
本帖最后由 yangxuefeng09 于 2014-06-20 16:32:38 编辑
// MFCFind.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "afxwin.h"

void Find( )
{
    CFileFind find;
    //查找文件
    BOOL bFind = find.FindFile( "C:\\windows\\*.*" );
    //循环获取并查找下一个
    while( bFind )
    {   
        //获取并查找下一个
        bFind = find.FindNextFile( );
        //判断类型
        if( find.IsDots( ) )
        {
            CString strName = find.GetFileName( );
            printf( "-----[%s]-------\n", (LPCSTR)strName );
        }
        else if( find.IsDirectory() )
        {
            CString strName = find.GetFileName( );
            printf( "+[%s]\n", (LPCSTR)strName );
/*请问 这里为什么要进行这种强制类型转换,把一个CString 类型的对象
强制的转换成为LPCSTR类型????有什么不同吗??*/
        }
        else
        {
            CString strName = find.GetFileName( );
            printf( " %s\n", (LPCSTR)strName );
        }
    }
    //关闭
    find.Close( );
}

int main(int argc, char* argv[])
{
    Find( );
return 0;
}


------解决方案--------------------
printf( " %s\n", (LPCSTR)strName );

读取 Cstring 时 可以这样用
------解决方案--------------------
LPCTSTR是CString的一个操作符,所以才可以