ホーム » VC » Windows C++ __argc __argv

2023年12月
 12
3456789
10111213141516
17181920212223
24252627282930
31  

カテゴリー

アーカイブ

ブログ統計情報

  • 80,553 アクセス



Windows C++ __argc __argv

MFC でコードを書いていて,コマンドライン引数を取りたくなった.
MFC では次の様にすれば取れるが,欲しいのは c の main に渡される argc と argv .
CString cmd_line = AfxGetApp()->m_lpCmdLine ;
検索すると次の所があった.欲しかった情報は __argc と __argv
【 VC++ MFC 】MFC でコマンドライン引数を利用する方法
次の様なコードを書いて動作を確認.

#include	<clocale>
#include	<iostream>
#include	<tchar.h>

#ifdef	_UNICODE
	#define		tin 		wcin
	#define		tout		wcout
	#define		terr		wcerr
	#define		tlog		wclog
#else
	#define		tin 		cin
	#define		tout		cout
	#define		terr		cerr
	#define		tlog		clog
#endif

int	_tmain	(int ,TCHAR* )
{
	_tsetlocale(LC_ALL,_T("")) ;
	{
		std::tout   		<< __argc      	<< std::endl ;
		for (int index=0 ; index<__argc ; index++) {
			std::tout	<< __targv[index]	<< std::endl ;
			}
		}
	return	0 ;
	}

Windwos C コマンドライン引数
_tmain が呼び出される前の mainCRTStartup の ::_setargv で設定されている.
::_setargv

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

1件のコメント

コメントは停止中です。

%d人のブロガーが「いいね」をつけました。