728x90
응용 프로그램을 아규먼트를 넘겨줘서 실행하고 싶을 때 _CHAR* argv 처리한다고 이렇게 만들고 저렇게 만들고
사람마다 다 다를 꺼라고 봅니다. 이것을 시간낭비하지 말고 program_options 를 이용해서 일관되게 만들면 서로
서로 불편할 일 없겠죠 :)
예제
#include "stdafx.h"
#include <boost\program_options.hpp>
namespace po = boost::program_options;
int _tmain(int argc, _TCHAR* argv[])
{
// 아규먼트 옵션에 대한 설명
po::options_description desc("사용가능한 옵션들");
desc.add_options()
("help", "도움말을 봅니다")
("ip", po::value<std::string>(), "접속할 서버의 ip 를 입력합니다")
;
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
// --help 가 있을 때 실행
if (vm.count("help"))
std::cout << desc << "\n"; // 설명을 출력
// --ip 가 있을 때 실행
if (vm.count("ip"))
{
std::string ip = vm["ip"].as<std::string>();
std::cout << "다음 ip 로 접속합니다. " << ip << std::endl;
}
else
std::cout << "접속할 ip 가 입력되지 않았습니다 default ip 로 접속합니다." << std::endl;
int n;
std::cout << "wait... " << std::endl;
std::cin >> n;
return 0;
}
아무것도 입력하지 않았을 때
아규먼트를 넣어봅시다. [ 실행파일.exe --help ] 이런식으로 배치파일을 만들거나 바로가기 방법 등등 마음대로 쓰세요 ^^
잘 동작하네요
728x90
'프로그래밍 > boost' 카테고리의 다른 글
| boost 라이브러리 설치 (0) | 2013.06.12 |
|---|---|
| boost::ptr_unordered_map (0) | 2013.05.24 |
| boost::function / boost::tuple 의 활용 (0) | 2012.11.07 |
| boost::tuple / tuples / tuples::tuple (0) | 2012.11.06 |
| boost::shared_ptr 과 Virtual Function 과 boost::timer (0) | 2012.10.25 |
댓글