J
Joe Van Dyk
#include <string>
#include <vector>
#include <iostream>
class Element
{
public:
Element(std::string n) : name_(n) {};
std::string serialize() const
{
return "<element>" + name_ + "</element>";
}
private:
std::string name_;
};
int main()
{
std::vector<Element> container;
container.push_back(Element("Joe"));
container.push_back(Element("Bob"));
std::string all_serialized;
std::vector<Element>::const_iterator iter;
// Is there a cooler way of doing this loop?
// Like with std::back_inserter or std::copy or something?
// Or perhaps create Element:perator<< ?
for (iter = container.begin(); iter != container.end(); ++iter)
{
all_serialized += iter->serialize();
}
std::cout << "All elements serialized: \n" << all_serialized
<< std::endl;
return EXIT_SUCCESS;
}
#include <vector>
#include <iostream>
class Element
{
public:
Element(std::string n) : name_(n) {};
std::string serialize() const
{
return "<element>" + name_ + "</element>";
}
private:
std::string name_;
};
int main()
{
std::vector<Element> container;
container.push_back(Element("Joe"));
container.push_back(Element("Bob"));
std::string all_serialized;
std::vector<Element>::const_iterator iter;
// Is there a cooler way of doing this loop?
// Like with std::back_inserter or std::copy or something?
// Or perhaps create Element:perator<< ?
for (iter = container.begin(); iter != container.end(); ++iter)
{
all_serialized += iter->serialize();
}
std::cout << "All elements serialized: \n" << all_serialized
<< std::endl;
return EXIT_SUCCESS;
}