在用vs寫win32的c++程序時是沒有命令行的,所以printf是不能用的。
但是調試的時候可以調用函數OutputDebugString來想vs的“輸出”窗口里輸出調試內容。像java中的System.out.println一樣往IDE的調試窗口里輸出信息。
OutputDebugString只接受字符串指針,如果要輸出其他格式,如int型,可以用sprintf把字符轉成字符串,在傳給OutputDebugString。
例子:
char chInput[512] ; sprintf(chInput,"int:%d\n",500); OutputDebugString( chInput );