Coding 小技巧

</pre>//格式化字符串的传递<p></p><p>#define  FSKILL_LOG(format ,...)   DREAMLAND_RUNINFO(L"[%s]"format,NBASKILL_LOGFILTER ,##__VA_ARGS__) </p><p>//字符串可以通过“”直接相连</p><p>printf( "[%s] "" File:%s, Line:%d\n", moduleName,__FILE__, __LINE__ );</p><p>//输入输出日志重定向</p><pre code_snippet_id="648986" snippet_file_name="blog_20150421_1_360780" name="code" class="cpp">/*
 File      : redirect.c
 Author    : Mike
 E-Mail    : Mike_Zhang@live.com
*/
#include <stdio.h>
#include <stdlib.h>

void test_stdin()
{
    char buf[128];
    freopen("1.txt", "r", stdin); //redirect stdin
    scanf("%s",buf);
    printf("%s\n",buf);
    freopen("CON", "r", stdin); //recover(Windows)
//freopen("/dev/console", "r", stdin); //recover(Linux)
//freopen("/dev/pts/0", "r", stdin); //recover stdin(Linux : my putty client)
    scanf("%s",buf);
    printf("%s\n",buf);
}

void test_stdout()
{
    freopen("1.txt", "w", stdout); //redirect stdout
    printf("test");
    freopen("CON", "w", stdout); //recover stdout(Windows)
//freopen("/dev/console", "w", stdout); //recover stdout(Linux)
//freopen("/dev/pts/0", "w", stdout); //recover stdout(Linux : my putty client)
    printf("OK\n");
}

int main()
{
    printf("Test stdout : \n");
    test_stdout();
    printf("Test stdin : \n");
    test_stdin();
    return 0;
}

// 查找字符

    stl_string wstrName = MultiByte2WideChar(purl);

    if (wstrName.find(_T("mem://")) != std::wstring::npos)
    {
        wstrFilePath = wstrName;
    }
    else
    {
        wstrFilePath += wstrName;
    }

//跳转的两种方式

do

{

}

while(0)

for(;;)

{

}

解除const属性

    // Cached global contest and SWF version fast access.
    mutable GASStringContext    StringContext;

N字节对齐:

大小:((size + (N - 1)) & ~(N - 1))

posted on 2015-04-21 09:59  KHacker  阅读(123)  评论(0编辑  收藏  举报