“非法块进入”与 yaml-cpp 中的 YAML 怪物示例

发布于 2025-01-03 04:08:46 字数 698 浏览 4 评论 0原文

我正在运行此处找到的示例来尝试在 C++ 中使用 YAML。我将代码逐字复制到新项目文件夹中的 test.cpp 中。我将 YAML 编译成静态库并将其链接到我的项目。我运行的是 Ubuntu 11.10。我使用以下命令进行编译:

    g++ -Wall -I. -g test.cpp -lyaml-cpp -L.

我得到以下错误语句:

    terminate called after throwing an instance of 'YAML::ParserException'
       what(): yaml-cpp: error at line 4, column 2: illegal block entry
    Aborted

这个异常是什么意思?可能出了什么问题?我找不到明确的文档来说明每个异常的含义,因此即使是此信息的链接也会有所帮助。我可能超出了我的能力范围,因为我对 YAML、使用库和 Linux 都是新手。预先感谢您的帮助。

编辑:错误发生在“parser.GetNextDocument(doc)”之前。另外,我从存储单个标量的网站上运行了一个更简单的示例,效果很好。异常是关于我的输入文件还是我的代码?

I am running the example found here to try out using YAML in C++. I copied the code verbatim into test.cpp in a new project folder. I compiled YAML into a static library and am linking it to my project. I'm running Ubuntu 11.10. I use the following command to compile:

    g++ -Wall -I. -g test.cpp -lyaml-cpp -L.

I get the following error statement:

    terminate called after throwing an instance of 'YAML::ParserException'
       what(): yaml-cpp: error at line 4, column 2: illegal block entry
    Aborted

What is the meaning of this exception? And what could be wrong? I couldn't find a clear documentation for what each of the exceptions could mean, so even a link to this information would be helpful. I am probably out of my depth, as I am new to YAML, using libraries, and linux for that matter. Thanks in advance for your help.

Edit: The error occurs before "parser.GetNextDocument(doc)". Also, I ran a simpler example from the website that stores a single scalar, and that worked fine. Is the exception about my input file, or my code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧竹 2025-01-10 04:08:46

该错误表明输入文件 (monsters.yaml) 存在问题。确保您准确地复制了它。它声称第 4 行第 2 列有错误,因此您可以先查看该位置(但 yaml-cpp 不太适合错误位置,因此这可能不是查看的正确位置)。

需要确保的事项:

  • 空格,而不是制表符
  • 缩进的适当空格数

The error indicates that there's a problem with the input file (monsters.yaml). Make sure you copied it exactly. It claims there's an error at line 4, column 2, so you can look at that spot first (but yaml-cpp isn't great with location of errors, so that may not be the right spot to look at).

Things to make sure about:

  • spaces, not tabs
  • the proper number of spaces for indentation
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文