【问题标题】:MQL5 error instead of printing the valuesMQL5 错误而不是打印值
【发布时间】:2018-03-23 09:27:21
【问题描述】:

我正在尝试以下代码:

void OnInit()
{
    int i = 0;
    string d[];
    while(i < 2)
    {
        ArraySetAsSeries(d,true);
        for (int j=0; j<5; j++)
        {
            if(MathMod(j,2)==0 && i==0)
                d[j] = "even";
            else if(MathMod(j,2)==0 )
                d[j] = "even without i zero";
            else
                d[j] = "odd";
        }
        i++;
    }
}

我愿意在测试中获得输出。但我收到以下错误:
2018.03.23 14:51:20.005 EURUSD,M1 (MetaQuotes-Demo): 基于真实生成

ticks
2018.03.23 14:51:20.006 EURUSD,M1: testing of Experts\testing lines and trdae.ex5 from 2018.02.01 00:00 to 2018.02.20 00:00 started
2018.03.23 14:51:20.050 2018.02.01 00:00:00   array out of range in 'testing lines and trdae.mq5' (61,2)
2018.03.23 14:51:20.051 OnInit critical error

请帮我摆脱这个问题并打印我愿意打印的数组。

【问题讨论】:

  • string d[]; 应该是编译时错误。
  • 你确定这是 C 而不是 C++? string 是什么?

标签: mql5 metatrader5


【解决方案1】:

在向数组中插入数据之前,您必须明确指出数组的大小。

使用ArrayResize(d,5); 就可以了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-26
    • 1970-01-01
    • 2018-05-16
    相关资源
    最近更新 更多