Ticket #9129: boostbug.cpp

File boostbug.cpp, 988 bytes (added by Roman Vaughan <nzsmartie@…>, 9 years ago)

Simple program demonstrating the bug

Line 
1#include <iostream>
2#include <string>
3#include <sstream>
4#include <boost/date_time.hpp>
5
6boost::gregorian::date testDate = boost::gregorian::day_clock::local_day();//(client.dateOfBirth);
7boost::gregorian::date_facet *format = new boost::gregorian::date_facet("%Y-%m-%d");
8std::ostringstream output1;
9std::wostringstream output2;
10
11int main(int argc, char **argv){
12 output1.imbue(std::locale(std::locale(),format));
13 output1 << testDate;
14 output2.imbue(std::locale(std::locale(),format));
15 output2 << testDate;
16 std::cout << "date: " << output1.str() << std::endl;
17 std::wcout << L"date: " << output2.str() << std::endl;
18
19 std::cout.imbue(std::locale(std::locale(),format));
20 std::cout << "date: " << testDate << std::endl;
21
22 std::wcout.imbue(std::locale(std::locale(),format));
23 std::wcout << L"date: " << testDate << std::endl;
24}
25/** Output:
26 *
27 * date: 2013-09-19
28 * date: 2013-Sep-19
29 * date: 2013-09-19
30 * date: 2013-Sep-19
31 *
32 */