00001
00007 #include <Utilitarios/ignoradores.H>
00008
00009 using namespace std;
00010
00011 istream& Utilitarios::operator>>(istream& entrada, Ignorador const& ignorador)
00012 {
00013 if(ignorador.deveLimparOCanal())
00014 entrada.clear();
00015
00016 char c;
00017 do
00018 entrada.get(c);
00019 while(entrada.good() and c != ignorador.terminador());
00020
00021 return entrada;
00022 }
00023
00024
00025 #ifdef TESTE
00026
00027 #include <fstream>
00028 #include <string>
00029 #include <cassert>
00030
00031 using namespace std;
00032 using namespace Utilitarios;
00033
00034 int main()
00035 {
00036 ofstream saida("ignoradores.lixo");
00037
00038 saida << 123 << endl
00039 << "Zé" << endl
00040 << "Lixo!" << endl
00041 << 456 << endl;
00042
00043 saida.close();
00044
00045 ifstream entrada("ignoradores.lixo");
00046
00047 int valor;
00048 entrada >> valor >> il;
00049
00050 assert(valor == 123);
00051
00052 string nome;
00053 getline(entrada, nome);
00054
00055 assert(nome == "Zé");
00056
00057 entrada >> valor;
00058
00059 #ifndef _STLP_IOSTREAM
00060
00061
00062
00063 assert(valor == 123);
00064 #endif
00065 assert(not entrada.good());
00066
00067 entrada >> ill >> valor;
00068
00069 assert(valor == 456);
00070 assert(entrada.good());
00071 }
00072
00073 #endif // TESTE
00074