003
14.08.2007, 18:14 Uhr
0xdeadbeef
Gott (Operator)
|
C++: |
#include <algorithm> #include <iostream> #include <iterator> #include <sstream> #include <string> #include <vector>
double convert_string(std::string const &s) { std::istringstream isstr; double result = 0.0;
isstr.str(s); isstr >> result;
return result; }
int main() { std::vector<std::string> numbers_s; std::vector<double> numbers_d;
numbers_s.push_back("1.1"); numbers_s.push_back("2.2"); numbers_s.push_back("3.3"); numbers_s.push_back("4.4");
std::transform(numbers_s.begin(), numbers_s.end(), std::back_inserter(numbers_d), convert_string);
std::copy(numbers_d.begin(), numbers_d.end(), std::ostream_iterator<double>(std::cout, "\n")); }
|
-- Einfachheit ist Voraussetzung für Zuverlässigkeit. -- Edsger Wybe Dijkstra |