xml
1<?xml version="1.0" encoding="utf-8"?> 2<faces> 3 <face id='0'> 4 <bounds x='41' y='49' width='426' height='426'/> 5 <right-eye x='161' y='208'/> 6 <left-eye x='336' y='208'/> 7 <features s-avg='0.76' s-min='0.40' s-max='0.93'> 8 <point id='PR' x='167' y='204' s='0.86'/> 9 <point id='F5' x='115' y='406' s='0.83'/> 10 <point id='F7' x='382' y='407' s='0.83'/> 11 </features> 12 </face> 13</faces> 14
c++
1struct Book { 2 std::string y; 3 std::string x; 4 5 Book() {} 6 7 Book(const Book& other) 8 : x(other.x),y(other.y) {} 9 10 Book(const std::string& x, const std::string& y) 11 : x(x),y(y){} 12 13 void print() const 14 { 15 std::cout << x << "," << y << std::endl; 16 } 17}; 18 19 20 21 22void load(const std::string& filename) 23{ 24 using boost::property_tree::ptree; 25 26 std::vector<Book> books; 27 28 ptree pt; 29 read_xml(filename, pt); 30 int i = 0; 31 char x[50], y[50]; 32 BOOST_FOREACH(const ptree::value_type& child_, pt.get_child("faces.face.features")) { 33 if (child_.first == "point") { 34 books.emplace_back(child_.second.get<std::string>("<xmlattr>.x"), child_.second.get<std::string>("<xmlattr>.y")); 35 x[i] = child_.second.get<char>("<xmlattr>.x"); 36 y[i] = child_.second.get<char>("<xmlattr>.y"); 37 i = i + 1; 38 printf("%s,%s", x[i], y[i]); 39 } 40 } 41 42} 43int main(int argc, char *argv[]) 44{ 45load("parts.xml"); 46return 0; 47} 48
このようにするとハンドルされていない例外が出てきてしまいます。
環境はvisual studio2017 15.8.1です。
プログラミング初心者なのでかみ砕いて教えていただけるとありがたいです。
よろしくお願いします。
x[i] = child_.second.get<char>("<xmlattr>.x");
の後にprintf("a")をすると表示されなくなるので、ここがおかしいようです。
x[i] = child_.second.get<char>("<xmlattr>.x");
のcharをdoubleにしてみると例外は消えるのですが文字化けしてしまいます。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/08 09:12
2018/11/08 09:31
2018/11/08 09:46
2018/11/08 09:49
2018/11/08 09:51