I have used the time_get<> facet's get_date() method to read a date from the following sources:
(i) cin and
(ii) an istringstream based on a string s whose value has been obtained from getline(cin, s).
The I/P from cin works fine; the date is read properly and printed fine.
However, the I/P from the istringstream gives an error; the date isn't read properly; an error occurs.
vector<string> locales {"C"};
/// Get I/P from a string.
void IPFromStr()
{
cout << "\nI/P from a string ... " << endl;
/// For each locale name
for (constauto& locs : locales)
{
cout << "locale name: " << locs << endl;
try
{
/// Create the locale.
locale loc {locs};
/// Read date/time parts from a string.
ReadDtPartFromStr(loc);
}
catch (const exception& e)
{
cerr << " Exception: " << e.what()
<< endl << endl;
}
}
}
/// Read date/time parts from a string.
void ReadDtPartFromStr(locale& loc)
{
/// Get the time_get<> facet.
const time_get<char>& tg =
use_facet<time_get<char>> (loc);
/// I/P string variable for the read date part.
string dtpart {};
/// output arguments for the time_get<> facet
struct tm d {}; /// time
ios_base::iostate err = ios_base::goodbit; /// good
getline(cin, dtpart);
cout << " dtpart: " << dtpart << endl;
/// Get an istringstream for the read date part
istringstream isdtpart {dtpart};
isdtpart.imbue(loc);
istreambuf_iterator<char> frm(isdtpart), end;
/// Read the date part.
tg.get_date(frm, end,
isdtpart,
err,
&d);
/// Print the date read.
Print(err, d);
}