Document.h
#include <vector> #include <list> #include <iostream> using std::list; using std::istream; using std::cin; using std::cout; typedef std::vector<char> Line; class Text_Iterator //ΠΈΡΠ΅ΡΠ°ΡΠΎΡ Π΄Π»Ρ ΠΊΠ»Π°ΡΡΠ° Document (ΡΠΎΡΡΠΎΠΈΡ ΠΈΠ· 2-Ρ
ΡΠ»Π΅Π½ΠΎΠ²) { list<Line>::iterator itLine; //ΡΡΡΠΎΠΊΠ° Π΄ΠΎΠΊΡΠΌΠ΅Π½ΡΠ° Line::iterator pos; //ΠΏΠΎΠ·ΠΈΡΠΈΡ Π² ΡΡΡΠΎΠΊΠ΅ public: Text_Iterator(list<Line>::iterator ll, Line::iterator pp) { itLine = ll; pos = pp; } Text_Iterator& operator++() { //Π΅ΡΠ»ΠΈ pos Π½Π° ΠΊΠΎΠ½ΡΠ΅ ΡΡΡΠΎΠΊΠΈ Π΄ΠΎΠΊΡΠΌΠ΅Π½ΡΠ°, ΠΏΠ΅ΡΠ΅Ρ
ΠΎΠ΄ΠΈΠΌ Π½Π° Π½Π°ΡΠ°Π»ΠΎ ΡΠ»Π΅Π΄ΡΡΡΠ΅ΠΉ, ΠΈΠ½Π°ΡΠ΅ Π½Π° ΡΠ»Π΅Π΄. ΡΠΈΠΌΠ²ΠΎΠ» pos if (++pos == itLine->end()) { ++itLine; pos = itLine->begin(); } else ++pos; return *this; }; Text_Iterator& operator--() { //Π΅ΡΠ»ΠΈ pos Π² Π½Π°ΡΠ°Π»Π΅ ΡΡΡΠΎΠΊΠΈ, ΡΠΎ ΡΡΠ°Π½ΠΎΠ²ΠΈΠΌΡΡ Π½Π° ΠΊΠΎΠ½Π΅Ρ ΠΏΡΠ΅Π΄. ΡΡΡΠΎΠΊΠΈ, ΠΈΠ½Π°ΡΠ΅ --pos if (pos == (itLine->begin())) { itLine--; pos = --(itLine->end()); } else --pos; return *this; }; char& operator*() { return *pos; } bool operator==(const Text_Iterator& arg) const { return (arg.pos == pos); } bool operator!=(const Text_Iterator& arg) const { return !(*this == arg); } //this Π½Π΅ Π·Π°ΠΏΠΎΠ»Π½Π΅Π½, ΠΏΠΎΡΠ΅ΠΌΡ? }; //ΠΊΠ»Π°ΡΡ ΡΠ΅ΠΊΡΡΠΎΠ²ΠΎΠ³ΠΎ Π΄ΠΎΠΊΡΠΌΠ΅Π½ΡΠ° struct Document { list<Line> List; Document() { List.push_back(Line()); } Text_Iterator begin() { return Text_Iterator(List.begin(), List.begin()->begin()); } Text_Iterator end() { list<Line>::iterator end = List.end(); end--; Line::iterator end_pos = end->end(); end_pos--; return Text_Iterator(end, end_pos); } //ΠΎΠΏΠ΅ΡΠ°ΡΠΎΡ Π²Π²ΠΎΠ΄Π° Π΄ΠΎΠΊΡΠΌΠ΅Π½ΡΠ° friend istream& operator >> (istream& is, Document& doc) { char input; int i(1); while (is.get(input)) { cout << "#" << i++ << ":" << input << "\n"; doc.List.back().push_back(input); if (input == '\n') //ΠΏΠΎΠ»ΡΡΠΈΠ»ΠΈ ΡΠΈΠΌΠ²ΠΎΠ» ΠΊΠΎΠ½ΡΠ° doc.List.push_back(Line()); } doc.List.back().push_back('\n');//Π΄ΠΎΠ±Π°Π²Π»ΡΠ΅ΠΌ ΡΡΠΎΠ±Ρ ΠΏΡΠΈΠΌΠ΅Π½ΡΡΡ back() return is; } }; When I bypass the container in a loop it does not correctly pass! =. I get assert (MSVS 2015) Main.cpp
int main(int argc, char* argv[]) { Document txt; cin >> txt; for (Text_Iterator it = txt.begin(); it != txt.end(); ++it) { cout << *it; } _getch(); return 0; }