Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue Parsing File with YAML-CPP
    primarykey
    data
    text
    <p>In the following code, I'm having some sort of issue getting my .yaml file parsed using <code>parser.GetNextDocument(doc);</code>. After much gross debugging, I've found that the (main) issue here is that my for loop is not running, due to <code>doc.size() == 0;</code> What am I doing wrong?</p> <pre><code>void BookView::load() { aBook.clear(); QString fileName = QFileDialog::getOpenFileName(this, tr("Load Address Book"), "", tr("Address Book (*.yaml);;All Files (*)")); if(fileName.isEmpty()) { return; } else { try { std::ifstream fin(fileName.toStdString().c_str()); YAML::Parser parser(fin); YAML::Node doc; std::map&lt; std::string, std::string &gt; entry; parser.GetNextDocument(doc); std::cout &lt;&lt; doc.size(); for( YAML::Iterator it = doc.begin(); it != doc.end(); it++ ) { *it &gt;&gt; entry; aBook.push_back(entry); } } catch(YAML::ParserException &amp;e) { std::cout &lt;&lt; "YAML Exception caught: " &lt;&lt; e.what() &lt;&lt; std::endl; } } updateLayout( Navigating ); } </code></pre> <p>The .yaml file being read was generated using yaml-cpp, so I assume it is correctly formed YAML, but just in case, here's the file anyways.</p> <pre><code>^@^@^@\230--- - address: ****************** comment: None. email: andrew(dot)levenson(at)gmail(dot)com name: Andrew Levenson phone: **********^@ </code></pre> <p><strong>Edit:</strong> By request, the emitting code:</p> <pre><code>void BookView::save() { QString fileName = QFileDialog::getSaveFileName(this, tr("Save Address Book"), "", tr("Address Book (*.yaml);;All Files (*)")); if (fileName.isEmpty()) { return; } else { QFile file(fileName); if(!file.open(QIODevice::WriteOnly)) { QMessageBox::information(this, tr("Unable to open file"), file.errorString()); return; } std::vector&lt; std::map&lt; std::string, std::string &gt; &gt;::iterator itr; std::map&lt; std::string, std::string &gt;::iterator mItr; YAML::Emitter yaml; yaml &lt;&lt; YAML::BeginSeq; for( itr = aBook.begin(); itr &lt; aBook.end(); itr++ ) { yaml &lt;&lt; YAML::BeginMap; for( mItr = (*itr).begin(); mItr != (*itr).end(); mItr++ ) { yaml &lt;&lt; YAML::Key &lt;&lt; (*mItr).first &lt;&lt; YAML::Value &lt;&lt; (*mItr).second; } yaml &lt;&lt; YAML::EndMap; } yaml &lt;&lt; YAML::EndSeq; QDataStream out(&amp;file); out.setVersion(QDataStream::Qt_4_5); out &lt;&lt; yaml.c_str(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload