csvからhtml表生成最強言語は?
■ このスレッドは過去ログ倉庫に格納されています
0074デフォルトの名無しさん
NGNG#include <iostream>
#include <string>
#include <sstream>
#include <functional>
#include <algorithm>
#include <boost/tokenizer.hpp>
template<typename T>
class table_writer :
public std::unary_function<std::basic_string<T>, void>
{
std::basic_ostream<T>& stream_;
public:
table_writer(std::basic_ostream<T>& stream)
: stream_(stream){ }
void operator()(std::basic_string<T> elem)
{ stream_ << "<td>" << elem << "</td>"; }
};
template<typename T>
void csv2html(
std::basic_istream<T>& in,
std::basic_ostream<T>& out)
{
boost::char_separator<T> d(",");
out << "<html><head><title></title></head><body><table border=1>";
std::basic_string<T> line;
while (!std::getline(in, line).eof()) {
boost::tokenizer<
boost::char_separator<T>,
std::basic_string<T>::const_iterator,
std::basic_string<T> > t(line, d);
out << "<tr>";
std::for_each(t.begin(), t.end(),
table_writer<T>(out));
out << "</tr>";
}
out << "</table></body></html>";
}
int main()
{
std::basic_ostringstream<char> ss;
csv2html<char>(std::cin, ss);
std::cout << ss.str();
return 0;
}
■ このスレッドは過去ログ倉庫に格納されています