코드에 명령 줄 옵션을 구현하려고합니다. 어떤 이유로, -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