天天看点

2014-03-13周四工作日志

待办:

       1、面试题。。。(已完成)

       2、以后想买一本书林锐的<<高质量C/C++编程>>

学到的新知识:

       1、没有用TEXT()的字符串在编译时,编译成ASII码,而经过TEXT()或者_T()调用的字符串在编译时,会被编译为Unicode。

       2、宏定义#define,

优点1:可以使复杂的内容更加简便,如#define pi 3.1415926。又如:#define M (a+b)

优点2:可以提高运行效率,但占的空间可能会很大。#即预处理命令,可以省去一些简单的函数调用问题。如:#define MAX( a, b )  ((a>b)?(a):(b))之后,可以直接使用MAX(4,5)。

  使用时应注意:1、可以定义表达式、常量。

2、不能用分号结尾,如果有分号,则会被系统误认为是要被定义 的字符串。

3、split分隔'\'

4、获得文件的属性(可读、只读等属性)可以用GetFileAttributes方法,GetFileAttributes("c:/www")的返回值是数值,不同的返回值对应不同的属性,当返回值为-1时,文件不存在。当返回值为其他值时,对应的属性参见http://hi.baidu.com/li0544/item/5c6a4f0872c7ac18ebfe3856

5、判断文件是否存在也可以用PathFileExists函数,如下:

#include <windows.h>
#include <iostream.h>
#include "Shlwapi.h"
 
void main(void)
{
    // Valid file path name (file is there).
    char buffer_1[ ] = "C:\\TEST\\file.txt"; 
    char *lpStr1;
    lpStr1 = buffer_1;
     
    // Invalid file path name (file is not there).
    char buffer_2[ ] = "C:\\TEST\\file.doc"; 
    char *lpStr2;
    lpStr2 = buffer_2;
     
    // Return value from "PathFileExists".
    int retval;
     
    // Search for the presence of a file with a true result.
    retval = PathFileExists(lpStr1);
    if(retval == 1)
    {
        cout << "Search for the file path of : " << lpStr1 << endl;
        cout << "The file requested \"" << lpStr1 << "\" is a valid file" << endl;
        cout << "The return from function is : " << retval << endl;
    }
     
    else
    {
        cout << "\nThe file requested " << lpStr1 << " is not a valid file" << endl;
        cout << "The return from function is : " << retval << endl;
    }
     
    // Search for the presence of a file with a false result.
    retval = PathFileExists(lpStr2);
     
    if(retval == 1)
    {
        cout << "\nThe file requested " << lpStr2 << "is a valid file" << endl;
        cout << "Search for the file path of : " << lpStr2 << endl;
        cout << "The return from function is : " << retval << endl;
    }
    else
    {
        cout << "\nThe file requested \"" << lpStr2 << "\" is not a valid file" << endl;
        cout << "The return from function is : " << retval << endl;
    }
}
           

6、((DWORD)-1)不仔细看还真以为是什么庞然大物呢!上网一搜才发现是对-1的强制类型转换。

继续阅读