Opened 10 years ago
Closed 10 years ago
#7828 closed Bugs (worksforme)
use BOOST_FOREACH push_back some thing into vector,the first value is blank.
| Reported by: | Owned by: | Eric Niebler | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | foreach |
| Version: | Boost 1.50.0 | Severity: | Problem |
| Keywords: | BOOST_FOREACH | Cc: |
Description
When I use BOOST_FOREACH push_back value into std::vector,the first value is blank.After this I have to erase the first element.
Change History (6)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
This ticket will get more interest if you:
- Post actual code
- Set the component to Boost.Foreach
- Set the "owned by" to the Boost.Foreach maintainer (eric_niebler); the list of maintainers
comment:3 by , 10 years ago
| Component: | None → foreach |
|---|---|
| Owner: | set to |
comment:5 by , 10 years ago
Sorry for reply late. The file name of xml document is "axml.xml".The content of the file like this:
<?xml version="1.0" encoding="UTF-8"?><client_set><client>00801038</client><client>00802980</client><client>01600817</client></client_set>
My code is like this:
std::vector<std::string> ClientSet; ... boost::property_tree::ptree pt; try { boost::property_tree::read_xml("axml.xml",pt); ... BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pt.get_child("client_set"))
ClientSet.push_back(v.second.data());
... } catch(std::exception & e) { }
comment:6 by , 10 years ago
| Resolution: | → worksforme |
|---|---|
| Status: | new → closed |
I tested the following code against Boost trunk:
#include <iostream>
#include <vector>
#include <string>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/foreach.hpp>
int main()
{
std::vector<std::string> ClientSet;
boost::property_tree::ptree pt;
try
{
boost::property_tree::read_xml("C:\\axml.xml",pt);
BOOST_FOREACH(
boost::property_tree::ptree::value_type &v,
pt.get_child("client_set"))
{
ClientSet.push_back(v.second.data());
}
std::cout << "client_set size = " << ClientSet.size() << std::endl;
std::cout << "client_set[0] = " << ClientSet[0] << std::endl;
std::cout << "client_set[1] = " << ClientSet[1] << std::endl;
std::cout << "client_set[2] = " << ClientSet[2] << std::endl;
}
catch(std::exception & e)
{ }
}
I used a data file C:\axml.xml that contains this:
<?xml version="1.0" encoding="UTF-8"?> <client_set> <client>00801038</client> <client>00802980</client> <client>01600817</client> </client_set>
I get this:
client_set size = 3 client_set[0] = 00801038 client_set[1] = 00802980 client_set[2] = 01600817
Looks ok to me.

I use BOOST_FOREACH paser a xml document.The xml document like this: <c>
</client_set>
I ues BOOST_FOREACH like this: std::vector<std::string> ClientSet; BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pt.get_child("client_set"))