Tôi đang sử dụng Ubuntu 14.04, sử dụng CMake và CLion. Tôi cố gắng để sử dụng chương trình Options, với đoạn mã sau lấy từ một ví dụ trong tài liệu hướng dẫn của họ:Tăng Program_Options ném "chuyển đổi ký tự thất bại"
#include <iostream>
#include <boost/program_options.hpp>
int main(int ac, char* av[]) {
namespace po = boost::program_options;
using namespace std;
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("compression", po::value<int>(), "set compression level")
;
po::variables_map vm;
po::store(po::parse_command_line(ac, av, desc), vm);
po::notify(vm);
if (vm.count("help")) {
cout << desc << "\n";
return 1;
}
if (vm.count("compression")) {
cout << "Compression level was set to "
<< vm["compression"].as<int>() << ".\n";
} else {
cout << "Compression level was not set.\n";
}
}
Khi tôi chạy nó, tôi nhận được kết quả sau từ nhà ga:
$ ./bin/webserver --help
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::logic_error> >'
what(): character conversion failed
Aborted (core dumped)
Tại sao mà không làm việc và làm thế nào tôi có thể giải quyết nó?
EDIT: Sau khi gỡ lỗi, tôi thấy rằng sự cố xuất phát từ dòng với store
, nếu đây là bất kỳ trợ giúp nào cho bạn. Ngoài ra, tôi có đề cập đến tôi đã cố gắng sử dụng store(..., true)
(thiết unicode
để true
)
Không có lỗi đối với tôi khi sử dụng g ++ 4.9.2 và Tăng 1.55. – rhashimoto
Tôi đang sử dụng Boost 1.60.0 – Victor