I have spend like one out in this example, and everytime I get the error Unable to read cin
with an ios_base::iostate
equal to failbit
from this code:
#include "dates.h"
#include <iostream>
#include <ctime>
#include <locale>
#include <sstream>
#include <iterator>
using namespace std;
void trasnlateDate(istream&in, ostream&out){
const time_get<char>& dateReader = use_facet<time_get<char> >(in.getloc());
ios_base::iostate state = static_cast<ios_base::iostate>(0);
istreambuf_iterator<char> end;
tm t;
dateReader.get_date(in, end, in, state, &t);
if(state == static_cast<ios_base::iostate>(0) || state == ios_base::eofbit){
const time_put<char>& dateWriter = use_facet<time_put<char> >(out.getloc());
char fmt[] = "%x";
if(dateWriter.put(out, out, out.fill(), &t, &fmt[0], &fmt[2]).failed())
cerr << "unable to write to output stream.\n";
}else{
cerr << "Unable to read cin.\n";
}
}
int main(){
locale::global(locale(""));
cin.imbue(locale("en_US.utf8"));
cout.imbue(locale("de_DE.utf8"));
trasnlateDate(cin, cout);
}
as always, gcc 4.4.3 in Ubuntu 10.4 x64