Men_In_Black

Junior Member | Редактировать | Профиль | Сообщение | ICQ | Цитировать | Сообщить модератору aleoizi Цитата: Интересная тема кстати, может кто что нибудь поизящнее предложет? | Код: #include <iostream> #include <vector> #include <algorithm> using namespace std; void main() { vector<int> array; array.push_back(1); array.push_back(2); array.push_back(3); array.push_back(4); array.push_back(5); copy(array.begin(), array.end(), ostream_iterator<int>(cout, "\r\n")); } | Вся прелесть в том, что можно похожим способом сделать так: Код: #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; void main() { vector<string> array; array.push_back("one"); array.push_back("two"); array.push_back("three"); array.push_back("for"); array.push_back("five"); copy(array.begin(), array.end(), ostream_iterator<string>(cout, "\r\n")); } | Или даже так: Код: #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; class Employee { string _name; string _address; public: Employee(const string& name, const string& address) : _name(name), _address(address) {} operator string() const { return "Employee name: " + _name + "\r\n" + "Employee address: " + _address + "\r\n"; } }; void main() { vector<Employee> array; array.push_back(Employee("John Smith", "7-th Avenue")); array.push_back(Employee("George Bush", "White House")); array.push_back(Employee("Bill Gates", "Microsoft Way")); copy(array.begin(), array.end(), ostream_iterator<string>(cout, "\r\n")); } | Или что-то вроде... Код: #include <vector> #include <algorithm> using namespace std; class Picture { ... public: Picture (const char *path) { ... } }; void DrawPicture(const Picture& picture) { ... } void main() { vector<Picture> array; array.push_back(Picture("C:\\мышка.jpg")); array.push_back(Picture("C:\\слоник.jpg")); array.push_back(Picture("C:\\гиппопотамчик.jpg")); for_each(array.begin(), array.end(), DrawPicture); } |  |