2006-06-24から1日間の記事一覧

行単位で読み込む input_iterator

行単位で読み込むinput_iteratorが見つからなかったので自作してみた。 なんかBoostのライブラリを組み合わせればできるような気もするけど。 #include <string> #incldue <iostream> #include <iterator> #include <boost/iterator/iterator_facade.hpp> template<typename CharType, typename Traits = std::char_traits<CharType> > class basic_istream_line_iterator : public b…</typename></boost/iterator/iterator_facade.hpp></iterator></iostream></string>

strdup

C

char *new_string(char *str){ char *new = (char *)malloc(strlen(str)+1); if (new == NULL) DIE_OUT_OF_MEMORY; strcpy(new, str); /* it's okay not to use strncpy */ return new; }なんで strdup を使わないのだろう。メモリ確保エラーの処理を一元化…