c++ - Cmake, Boost parsing command line -
i have problem. using cmake , boost vs 2015.
i intend develop tool using cgal , assimp. convert file formats own. however, encountered problem , might simple cant see it.
when press f5, debug error 2 images have attached. have attached code. pictures here:
#include <boost/asio.hpp> #include <boost/filesystem/path.hpp> #include <boost/iostreams/device/file_descriptor.hpp> #include <boost/iostreams/stream.hpp> #include <boost/program_options.hpp> #include <boost/system/error_code.hpp> #include <iostream> #include <sstream> #include <string> struct cmdoptions { std::string input, output, directory; int points; }; namespace po = boost::program_options; bool process_command_line(int argc, char **argv, cmdoptions &cmdoptions1) { if (argv == nullptr) { return false; } try { po::options_description desc("program usage"); po::options_description desc ("program usage"); desc.add_options() ("halp, h", "halp!") ("input, i", po::value<std::string>(&cmdoptions1.input), "specify input") ("output, o", po::value<std::string>(&cmdoptions1.output) ,"specify output") ("points, p", po::value<int>(&cmdoptions1.points), "% of reduced points") ("directory, d", po::value<std::string>(&cmdoptions1.directory)->required(), "set directory"); po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); po::notify(vm); if (vm.count("help")) { std::cout << desc << std::endl; return false; } // trolololol xd if (vm.count("input")) { &cmdoptions1.input; } if (vm.count("output")) { &cmdoptions1.output; } if (vm.count("points")) { &cmdoptions1.points; } if (vm.count("directory")) { &cmdoptions1.directory; } } catch (std::exception &e) { std::cerr << "error: " << e.what() << std::endl; return false; } catch (int e) { std::cerr << "unknown error!" << e << std::endl; return false; } return true; } int main(int argc, char **argv, cmdoptions &cmdoptions1) { bool result = process_command_line(argc, argv, cmdoptions1); if (!result) return -1; std::cout << "input" << &cmdoptions1.input << std::endl; std::cout << "output" << &cmdoptions1.output << std::endl; std::cout << "points" << &cmdoptions1.points << std::endl; std::cout << "directory\t" << &cmdoptions1.directory << std::endl; }
your cmdoptions1
uninitialized.
in fact, main
should not compile (what kind of signature that?).
besides, you're printing pointers config values.
thirdly, compiler doesn't intent when type trololol xd
.
#include <boost/asio.hpp> #include <boost/filesystem/path.hpp> #include <boost/iostreams/device/file_descriptor.hpp> #include <boost/iostreams/stream.hpp> #include <boost/program_options.hpp> #include <boost/system/error_code.hpp> #include <iostream> #include <sstream> #include <string> struct cmdoptions { std::string input, output, directory; int points; }; namespace po = boost::program_options; bool process_command_line(int argc, char **argv, cmdoptions &cmdoptions1) { if (argv == nullptr) { return false; } try { po::options_description desc("program usage"); desc.add_options() ("halp, h", "halp!") ("input, i", po::value<std::string>(&cmdoptions1.input), "specify input") ("output, o", po::value<std::string>(&cmdoptions1.output) ,"specify output") ("points, p", po::value<int>(&cmdoptions1.points), "% of reduced points") ("directory, d", po::value<std::string>(&cmdoptions1.directory)->required(), "set directory"); po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); po::notify(vm); if (vm.count("help")) { std::cout << desc << std::endl; return false; } } catch (std::exception &e) { std::cerr << "error: " << e.what() << std::endl; return false; } catch (int e) { std::cerr << "unknown error!" << e << std::endl; return false; } return true; } int main(int argc, char **argv) { cmdoptions cmdoptions1; bool result = process_command_line(argc, argv, cmdoptions1); if (!result) return -1; std::cout << "input" << cmdoptions1.input << std::endl; std::cout << "output" << cmdoptions1.output << std::endl; std::cout << "points" << cmdoptions1.points << std::endl; std::cout << "directory\t" << cmdoptions1.directory << std::endl; }
Comments
Post a Comment