namespace po = boost::program_options; po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("letter", po::wvalue<std::wstring>(), "set disk letter")
("ip",po::value<std::string>(),"set briefcase server ip address")
; po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm); po::notify(vm); if (vm.count("help")) {
std::cout << desc << "\n";
return 1;
} std::wstring mount_point = L"G:";
std::string bc_server_ip = ""; if(vm.count("letter")) mount_point = vm["letter"].as<std::wstring>();
if(vm.count("ip") ) bc_server_ip = vm["ip"].as<std::string>();
用红色标注的如何该成windows 应用程序呀,在控制台上还有argc,argv,但是在应用程序中没有呀,怎么办呀。
{
int n = __argc;
for(int i = 1 ; i < n ; i++)
{
AfxMessageBox(__targv[i]);
}
}
Unicode console process written in C can use the wmain or _tmain function to access the command-line arguments. Unicode GUI applications must use the GetCommandLineW function to access Unicode strings.
LPWSTR *CommandLineToArgvW( LPCWSTR lpCmdLine,
int *pNumArgs
);
自己处理一下呗
#include <windows.h>
#include <stdio.h>
#include <shellapi.h>
int __cdecl main()
{
LPWSTR *szArglist;
int nArgs;
int i;
szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
if( NULL == szArglist )
{
wprintf(L"CommandLineToArgvW failed\n");
return 0;
}
else
{
for( i=0; i<nArgs; i++)
printf("%d: %ws\n", i, szArglist[i]);
LocalFree(szArglist);// Free memory allocated for CommandLineToArgvW arguments.
return(1);
}
}
int argc ;
wchar_t ** argv = CommandLineToArgvW( GetCommandLine() , &argc
);
只不过你得自己处理一下宽字符到 ansi 的转换。
po::store(po::parse_command_line(argc, argv, desc), vm);这行怎么改,我按照14楼说的做了,老上重启电脑了