jackee1234:
I hope to write a function PrintVars that is able to print the print variables with their names. e.g.,
The output to the console is:
The difficulty here is to
- Get the variable name;
- passing parameters of various types to the function.
Is there a way to achieve 1 and 2?
#define PRINTVAR(v) printf("%s = %s",#v,(string)v) int var1=1; bool var2=true; int var3=2; //PrintVars(var1,var2,var3); PRINTVAR(var1); PRINTVAR(var2); PRINTVAR(var3);
Alain Verleyen:
Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий
Получение значений открытого интереса не для текущего бара
fxsaber, 2016.09.05 15:06
#define TOSTRING(A) #A + " = " + (string)A
Print(TOSTRING(Var1));
Alain Verleyen:
#define PRINTVAR(v) printf("%s = %s",#v,(string)v) | I never think about the stringizing operator since it isn't in the documentation. |
MQL5: universal Print
Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий
fxsaber, 2016.11.10 10:42
class PRINTCLASS
{
public:
template <typename T>
static void MyPrint( const T &Value )
{
T Array[1];
Array[0] = Value;
::ArrayPrint(Array);
}
template <typename T>
static void MyPrint( const T Value )
{
::Print(Value);
}
};
#define Print(A) PRINTCLASS::MyPrint(A)
void OnStart()
{
MqlTick Tick;
SymbolInfoTick(_Symbol, Tick);
Print(Tick);
int i = 5;
Print(i);
}
{
public:
template <typename T>
static void MyPrint( const T &Value )
{
T Array[1];
Array[0] = Value;
::ArrayPrint(Array);
}
template <typename T>
static void MyPrint( const T Value )
{
::Print(Value);
}
};
#define Print(A) PRINTCLASS::MyPrint(A)
void OnStart()
{
MqlTick Tick;
SymbolInfoTick(_Symbol, Tick);
Print(Tick);
int i = 5;
Print(i);
}
Result
[time] [bid] [ask] [last] [volume] [time_msc] [flags] [0] 2017.05.09 19:36:20 1.08745 1.08749 0.0 0 1494358580466 96 5
Alain Verleyen:
Thanks, I learnt something new today

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I hope to write a function PrintVars that is able to print the print variables with their names. e.g.,
The output to the console is:
The difficulty here is to
Is there a way to achieve 1 and 2?