How do I define a constant in C ++?
I have executed a linux program on windows via Mingw. However, the transformation was not perfect. For example, on Windows, this is the output (I get "zu" instead of real numbers):
Approximated minimal memory consumption:
Sequence : zuM
Buffer : 1 X zuM = zuM
Table : 1 X zuM = zuM
Miscellaneous : zuM
Total : zuM
It turns out Mingw doesn't support% zu, but it does offer a workaround. The website says:
This won't work since you are using Microsoft's implementation. Use mingw_printf directly or define USE_MINGW_ANSI_STDIO to 1 up to including stdio.h.
So, I did a search in my program and I found that cdhit-common.h is the only file that has the #include line. So, I defined USE_MINGW_ANSI_STDIO above this line and compiled:
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdlib>
#define USE_MINGW_ANSI_STDIO 1
#include<stdio.h>
...
It compiles, but the program still prints "zu" instead of numbers. It's okay, what have I done? Why didn't it work?
Note. The solution with USE_MINGW_ANSI_STDIO is for mingw64 while I am using mingw. I hope for both platforms.
source to share
You are setting the pre-processor flag. This means that when the compiler reads <stdio.h>
, it will have USE_MINGW_ANSI_STDIO
it set to 1. This will potentially be used in a compiler directive #if
or #ifdef
.
It is usually preferable to put these flags in your flag compilations, eg.
-DUSE_MINGW_ANSI_STDIO=1
rather than code.
(Note: it may be -D__USE_MINGW_ANSI_STDIO=1
)
If you put it in code, do it either
- In a header that is always included before anything else, such as some platform related header.
- Before other is included in your file.
It is possible that one of the C ++ stream headers implements using <stdio.h>
source to share