0

I am trying to show in an edit box a program execution time. I have found some examples at Stackoverflow like the code here below.

using namespace std;
using namespace date;
ostringstream out;
auto start = chrono::system_clock::now();

//some program execution

auto finish = chrono::system_clock::now();
out << finish - start;
string s = out.str();
cout << s << '\n';

I have installed the library #include <date/date.h> via vcpkg. But the problem is: as soon as I do #include <date/date.h>, and run code with Local Windows Debugger a numerous mistake is happening as indicated in the snap shot below.

enter image description here

I mean, simple including of <date/date.h> library leads to errors.

How can I avoid this issue?

Many thanks in advance!

UPD

#include "pch.h"
#include "framework.h"
#include "MFCApplication2.h"
#include "MFCApplication2Dlg.h"
#include "afxdialogex.h"
#include <iostream>
#include <date/date.h>

void CMFCApplication2Dlg::OnBnClickedButton1()
{

    //I have cleared the code inside, but errors yet appear

}
newman
  • 149
  • 10
  • Please show a complete [mre]. You are not including the file anywhere in the shown code. – user17732522 Apr 04 '22 at 11:23
  • 3
    Does this answer your question? [Why is std::min failing when windows.h is included?](https://stackoverflow.com/questions/5004858/why-is-stdmin-failing-when-windows-h-is-included) – Öö Tiib Apr 04 '22 at 11:28
  • @user17732522 Its just an empty MFC based dialogue. The errors appear as soon as I put #include and run the program – newman Apr 04 '22 at 12:02
  • @NewMan The important detail here is that you are directly or indirectly including `windows.h` before `date.h`. The header file `date.h` uses `min` and `max` as names for functions in the line mentioned in the error messages. The comment above yours links to an explanation why that doesn't work by default when `windows.h` is included. – user17732522 Apr 04 '22 at 12:05
  • 1
    Also, see the issues list of the library: https://github.com/HowardHinnant/date/issues/437, https://github.com/HowardHinnant/date/issues/383, https://github.com/HowardHinnant/date/issues/87, https://github.com/HowardHinnant/date/issues/19, https://github.com/HowardHinnant/date/issues/602 – user17732522 Apr 04 '22 at 12:09
  • I will carefully examine your kind replies. Many thanks! – newman Apr 04 '22 at 12:14
  • In my case #define NOMINMAX did not help, but #undef min and #undef max worked fine. Thank you for the right suggested direction! – newman Apr 04 '22 at 13:57
  • Try defining `NOMINMAX` in the IDE like this: https://learn.microsoft.com/en-us/cpp/build/working-with-project-properties?view=msvc-170#to-create-a-user-defined-macro – Howard Hinnant Apr 05 '22 at 13:23

0 Answers0