SHOW ME THE CODE !

from long string to substrings:
    //split a long string into substrings
    // use of break and continue
    unsigned short nSubStrings {8};
    string* ayrFx = new string[nSubStrings + 1];
    string line;
    line = "       USD PEN     MXN    BRL   ARS    CLP    COP EUR";
    unsigned short j {0}, i{0};
    for (; i < line.length(); i++) {
        //cout << line[i] << " ";
        if (line[i] == ' ') continue;
        while(line[i]) {
            ayrFx[j] += line[i];
            i++;
            if (line[i] == ' ') break;
        }
        j++;
    }
 
    for (j = 1; j <= nSubStrings; j++) {
        cout << "\n\tj:" << j << "  " << ayrFx[j];
    }
 
    OUTPUT:
    j:1      USD
    j:2      PEN
    j:3      MXN
    j:4      BRL
    j:5      ARS
    j:6      CLP
    j:7      COP
    j:8      EU

REF:

Systematic Forex Trading

Do we not need to declare the variable “i” inside the for loop?

C++:
 for (int i = 0; …

Similarly,
C++:
 for (int j = 1; …

I remember, from the QuantNet course, that in C, if we declare the counter variable once, we don’t need to re-declare again.
 
Last edited:
Ohh I just saw that both i and j have been declared above.
C++:
 unsigned short j {0}, i{0};
I didn’t know that variables can be declared in this way though. Quite interesting!! :)
 
1658671638231.png
 
Top