掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
ファイルの中で改行するには? (ID:50211)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
よく考えたら,bの方法は使えないね……。 istreamline_iteratorでも作るか。 #include <iterator> #include <string> #include <istream> #include <memory> #if defined(_MSC_VER) && _MSC_VER < 1300 && !defined(STD_PTRDIFF_T_DEFINED) #define STD_PTRDIFF_T_DEFINED namespace std { using ::ptrdiff_t; } #endif template <typename T, class Ch = std::char_traits<T>, class A = std::allocator<T>, typename D = std::ptrdiff_t> class istreamline_iterator : public std::iterator<std::input_iterator_tag, T, D #if !defined(_MSC_VER) || _MSC_VER >= 1300 , const std::basic_string<T, Ch, A> *, const std::basic_string<T, Ch, A> & #endif > { typedef istreamline_iterator<T, Ch, A, D> this_type; public: typedef T char_type; typedef Ch traits_type; typedef std::basic_istream<T, Ch> istream_type; typedef std::basic_string<T, Ch, A> string_type; istreamline_iterator (void) : in_stream(0) {} istreamline_iterator (istream_type & s) : in_stream(&s) {} const string_type & operator* (void) const { return value; } const string_type * operator-> (void) const { return &(operator*()); } this_type & operator++ (void) { std::getline(*in_stream, value); if (in_stream->eof()) in_stream = 0; return *this; } this_type operator++ (int) { this_type tmp = *this; ++*this; return tmp; } bool operator== (const this_type & rhs) const { return in_stream == rhs.in_stream; } bool operator!= (const this_type & rhs) const { return !(*this == rhs); } private: istream_type * in_stream; string_type value; }; こんな感じかな? たぶん,istream_itertorと同じように使えるはず。
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.