[問題] _tmain 和 main 中的 Command Line Arg

看板C_and_CPP (C/C++)作者 (王者:一條孤獨的不歸路)時間16年前 (2009/07/12 20:56), 編輯推噓2(207)
留言9則, 4人參與, 最新討論串1/1
IDE環境:VS2008 C++ Express int main( int argc, _TCHAR *argv[]) { int count; // Display each command-line argument. for( count = 0; count < argc; count++ ) { printf("%s\n", argv[count]); } } 若上述的程式碼產生的執行檔為 Test.exe 當我在 Visual Studio 2008 Command Prompt 下 Test.exe Test1 test2 執行的結果為 Test.exe Test1 test2 int _tmain( int argc, _TCHAR *argv[]) { int count; // Display each command-line argument. for( count = 0; count < argc; count++ ) { printf("%s\n", argv[count]); } } 若上述的程式碼產生的執行檔為 Test.exe 當我在 Visual Studio 2008 Command Prompt 下 Test.exe Test1 test2 執行的結果為 T T t 我的疑問是為什麼在 _tmain 裡, 程式執行的結果會只輸出 Command Line Argument 的第一個字元, 而不是整個 Argument 的字串名稱? -- http://blog.pixnet.net/pinglunliao Something About Game Programming http://www.wretch.cc/blog/pinglunliao 白爛文 http://pinglunliao.spaces.live.com/ 新的希望 http://blog.roodo.com/pinglunliao -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 125.224.200.127

07/12 21:02, , 1F
wprintf
07/12 21:02, 1F

07/12 21:03, , 2F
改成 _tprintf(_T("%s\n"), argv[count]);
07/12 21:03, 2F

07/12 21:50, , 3F
還不知道 _tmain 跟 _TCHAR 是什麼之前最好不要去用,搞懂再用
07/12 21:50, 3F

07/12 21:50, , 4F
有底線的名稱通常代表不是標準,大寫代表巨集
07/12 21:50, 4F

07/12 21:51, , 5F
對了,微軟的東西,都可以在 msdn 查到資料
07/12 21:51, 5F

07/12 23:47, , 6F
_t代表unicode / ANSI code的自動切換巨集...
07/12 23:47, 6F

07/12 23:48, , 7F
當專案設定為(define)UNICODE, 他會自動切成W系列(wide)
07/12 23:48, 7F

07/12 23:49, , 8F
否則會用A系列取代(ANSI), 相關的巨集還有T2CA/T2CW/A2CT等
07/12 23:49, 8F

07/12 23:49, , 9F
稍微弄懂後就會覺得很好用了...會用即可(其實也很簡單寫啦)
07/12 23:49, 9F
文章代碼(AID): #1AMTrrRw (C_and_CPP)
文章代碼(AID): #1AMTrrRw (C_and_CPP)