在使用VC++时,经常使用OutputDebugString往往Output窗口写一些调试信息,如果输出信息遵循某种格式,那么在Output窗口中点击相应输出文本就会跳到相应的代码行中。具体格式MSDN中有说,简单的说法,在输出文本的最前面是"文件名(行号):"的格式就可以了。一个例子,用在我的内存泄露检测代码中:
 wsprintf(output_temp,
      
      
        "
      
      
        %s(%d):>>>>>>>>>>>>memleaks!size=%d 
      
      
        "
      
      
        ,
      
        wsprintf(output_temp,
      
      
        "
      
      
        %s(%d):>>>>>>>>>>>>memleaks!size=%d 
      
      
        "
      
      
        ,
         memory_allocated[i].file,
        memory_allocated[i].file,
         memory_allocated[i].line,
        memory_allocated[i].line,
         memory_allocated[i].size);
        memory_allocated[i].size);
         OutputDebugString(output_temp);
        OutputDebugString(output_temp);
      
    重点在于 %s(%d): 一定是在最前面,而且冒号是不能少的。当然提供的file和line必须是正确的,使用编译器提高的__FILE__和__LINE__就可以了。


 
					 
					