This example uses the date library without any using namespace
:
#include <iostream>
#include <date/date.h>
//using namespace std;
//using namespace date;
int main() {
date::year_month_day startDate = 2018_y / 1 / 6;
std::cout << startDate << '\n';
return 0;
}
but does not compile, error: unable to find numeric literal operator 'operator""_y'
How to use this library without using namespace
?
UPDATE:
I changed the code as follows, but there are still many errors.
#include <iostream>
#include <date/date.h>
int main() {
date::sys_time<std::chrono::nanoseconds> tp;
std::istringstream in1{"2018-12-21 01:15:31"};
in1 >> date::parse("%F %T", td);
std::cout << tp << '\n';
return 0;
}
error: no match for 'operator<<' (operand types are 'std::ostream' {aka 'std::basic_ostream'} and 'date::sys_time ...
Numeric literal operator 'operator""_y' is declared inside of namespace 'date'.
You can use 'using namespace date' or 'using namespace date::literals'
More information: How to refer to user defined literal operator inside a namespace?
#include <iostream>
#include <date/date.h>
int
main()
{
using namespace date::literals;
date::year_month_day startDate = 2018_y / 1 / 6;
std::cout << startDate << '\n';
}
And:
#include <iostream>
#include <date/date.h>
int
main()
{
date::sys_time<std::chrono::nanoseconds> tp;
std::istringstream in1{"2018-12-21 01:15:31"};
in1 >> date::parse("%F %T", tp);
using date::operator<<;
std::cout << tp << '\n';
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.