2011-02-01 14 views
9

boost:program_optionsでコマンドライン解析に問題があります。boost :: program_optionsでLPTSTR *コマンドライン引数を解析する

const std::vector<tstring> args; 
if (ac > 0 && NULL!=av) //ac is a ULONG 
{ 
    for (int i = 0; i < ac; i++) 
    { 
     args.push_back(av[i]); //av is an LPTSTR pointer (pointer to TCHAR*) 
    } 

    } 
    po::command_line_parser parser(args); 

をパーサーのctorがconstのSTDを取ることになっている::私のプログラムのベクトル<チャート>

typedef basic_command_line_parser<char> command_line_parser; 
typedef basic_command_line_parser<wchar_t> wcommand_line_parser; 

/** Creates instance of 'command_line_parser', passes parameters to it, 
    and returns the result of calling the 'run' method.   
*/ 
template<class charT> 
    class basic_command_line_parser : private detail::cmdline { 
    public: 
     /** Creates a command line parser for the specified arguments 
      list. The 'args' parameter should not include program name. 
     */ 
     basic_command_line_parser(const std::vector< 
            std::basic_string<charT> >& args); 

tstringは

です:それはそうコードを示すようになって説明する最も簡単な方法
typedef std::basic_string<TCHAR> tstring; 

私が手にエラーがある:

Error 16 error C2664: 'boost::program_options::basic_command_line_parser<charT>::basic_command_line_parser(const std::vector<_Ty> &)' : cannot convert parameter 1 from 'const std::vector<_Ty>' to 'const std::vector<_Ty> &' myfile.cpp 329 

ここで、どこで、私は迷っていますか?私はあらゆる種類のキャストと再定義を試みましたが、何も機能しておらず、私はテザーの最後にいます。

編集@Zac:ちょうど私は、Visual Studio 2008のVC9コンパイラ

を使用していますことを指摘し

Error 14 error C2664: boost::program_options::basic_command_line_parser<charT>::basic_command_line_parser(const std::vector<_Ty> &)' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'const std::vector<_Ty> &' MyFile.cpp 328 

編集 :あなたが提案された変更を作る
...私はエラーを取得します

答えて

5

あなたはUnicodeのビルドを使用しているように見えるので、明示的にワイド文字のバージョンのいずれかを使用:

po::wcommand_line_parser parser(args); 

以上の可撓性:

po::basic_command_line_parser<TCHAR> parser(args); 
+0

それはゲオルグです。 tcommand_line_parserをtypedefにします。 ありがとうございます。 – Dennis

2

あなたが道に迷って行った行は以下の通りです:

const std::vector<tstring> args; 

変更し、それに:

std::vector<tstring> args; 
+2

を@デニス:パーサ定数はconst&によってベクトルをとっていますが、それが渡すベクトルはconstである必要はありません。それはctorがベクトルを変更しないことを意味します。これは、この答えがあなたの不要なconstを取り除く理由です。これは後でpush_backでベクトルを修正しようとするとエラーになります。 –

+0

Fred ... spot on。 ザック...いいえ。これは私のプログラムの最初の反復でした。質問欄の編集を参照してください。 – Dennis

+0

@Dennis:プロジェクト設定でUNICODEビルドオプションがオフになっていることを確認してください。 –

関連する問題