我试图在我的代码中实现命令行选项。出于某种原因,我的-a选项可以正常工作,但我的-c选项无法正常工作,即使它们基本相同。当我尝试使用-c选项运行我的代码时,我收到以下消息。命令行参数问题
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct NULL not valid
Aborted
以下是我的代码。
int c;
std::string config = def+std::string("SamplesConfig.xml");
std::string cal = def+std::string("calibration.bin");
while ((c = getopt(argc, argv, "a:c"))>=0)
{
switch(c)
{
case 'a':
{
config = std::string(optarg);
printf("%s", (char *)config.c_str());
break;
}
case 'c':
{
cal = std::string(optarg);
printf("%s", (char *)cal.c_str());
break;
}
default:
{
break;
}
}
}
你能减少这一切吗?你知道哪一行代码实际上是在抛出错误吗?你有调试过吗? – SirPentor 2012-07-13 16:38:25