Skip to content

Commit 60bac19

Browse files
authored
Create example_usage.md
1 parent 54f025c commit 60bac19

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

doc/example_usage.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
# An {fmt} wrapper around OutputDebugString makes sending formatted message much more plesant.
3+
```
4+
#include <fmt/format.h>
5+
6+
#include <sstream>
7+
#include <string_view>
8+
9+
void OutputDebugString(const char * message)
10+
{
11+
fmt::print("{}", message);
12+
}
13+
14+
void DebugMessage(std::string_view message)
15+
{
16+
OutputDebugString(message.data());
17+
}
18+
19+
template <typename... Args>
20+
void DebugMessage(std::string_view format, Args &&... args)
21+
{
22+
auto formatted = fmt::vformat(format, fmt::make_args_checked<Args...>(format, std::forward<Args>(args)...));
23+
OutputDebugString(formatted.data());
24+
}
25+
26+
int main()
27+
{
28+
DebugMessage("test");
29+
DebugMessage("[{}]", 42);
30+
return 0;
31+
}
32+
```

0 commit comments

Comments
 (0)