Created
December 13, 2016 16:38
-
-
Save mtao/2c3059831e961190eb5f37bf60675ecc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
#include <iterator> | |
#include <vector> | |
#include <sstream> | |
template <typename T> | |
std::string to_csv(const std::vector<T>& vec) { | |
std::stringstream ss; | |
std::copy(vec.begin(),vec.end()-1,std::ostream_iterator<T>(ss,",")); | |
ss << vec.back(); | |
return ss.str(); | |
} | |
int main() { | |
std::vector<int> a = {0,1,2,3}; | |
std::vector<double> b = {1,1,2,3,5}; | |
std::cout << to_csv(a) << std::endl; | |
std::cout << to_csv(b) << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment