Noting the dates of the above replies, it may be a bit late for the OP ;-)
But in the hope that it may help others, here is what I found in 2023:
https://stackoverflow.com/questions/36418307/visual-c-detect-if-the-program-is-loaded-into-the-visual-debugger[
^]
In case that link gets broken, here's an example:
if (IsDebuggerPresent()) printf("Eureka!");
It works in VS2019 under Windows 10, and googling "IsDebuggerPresent" gets you straight to the Microsoft documentation.
--Jon.