可以从命令行运行C++代码,但不能从visual studio中的调试模式运行

can run C++ code from command line but not from debug mode in visual studio

本文关键字:运行 studio 调试 模式 visual 命令行 C++ 代码 但不能      更新时间:2023-10-16

我在调试模式下编译了下面的程序,没有任何错误。我可以从命令行运行.exe文件,但当我尝试在visualstudio中调试代码时,异常会从行抛出

DetectionInternalSettings* internal_settings =
           DetectionInternalSettingsFactory::createFromFileSystem(
                  "C:/data/card_detection_engine.yaml");

任何以前遇到过这种情况的人,在命令行和调试模式下运行时的行为都不同。

int main(int argc, char **argv) 
{
    DetectionSettings settings;
    try
    {
        DetectionInternalSettings* internal_settings =
        DetectionInternalSettingsFactory::createFromFileSystem("../data/card_detection_engine.yaml");
    }
    catch (const MyException &e)
    {
        fprintf(stderr, "Exception raised: %sn", e.what().c_str());
        return 1;
    }
    return 0;
}

我还讨论了异常的详细信息,这里是ocrcarddetectionengine_sample.exe:Microsoft C++异常:YAML::TypedBadConversion内存位置0x003FF0D0中0x76E1C41F处的First chance异常。

createFromFileSystem 相关的更多代码

DetectionInternalSettingsFactory::createFromFileSystem(const std::string &configPath)  throw (MyException)
{
  return new DetectionInternalSettingsImpl(configPath);
}
struct DetectionInternalSettingsImpl : public DetectionInternalSettings {
    DetectionInternalSettingsImpl(const std::string &config_path) {
        if (config.ReadFromFilesystem(config_path)) {
            throw MyException("Bad configuration path.");
        }
    }
    ~DetectionInternalSettingsImpl() { }
    Core::Detector::Configuration config;
};

信任调试模式异常。它更彻底地测试代码实际在做什么,而命令行只是在等待问题发生。

在您的情况下,它们似乎不会发生,可能是因为您没有对指针变量执行任何操作。