C++: Error C2065, C2131, a non-constant (sub-)expression was encountered : <p>I was trying to make a program that get user's integer input and then filter every single digit in that int into even number and odd number. There is no any mistake when I finished the code but error comes out when I run it.</p>

<p>My code: </p>

<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;array&gt;
#include &lt;stdio.h&gt;
#include &lt;cstring&gt;
#include &lt;sstream&gt;
using namespace std;

int main() {
    int input = NULL;
    int EvenNumbering = 0;
    int OddNumbering = 0;

    cout &lt;&lt; "Please input a number: ";
    cin &gt;&gt; input;

    string str = to_string(input); //Convert it to string
    char cstr[str.length];
    int EvenNo[str.length];
    int OddNo[str.length];

    strcpy(cstr , str.c_str()); //Put it into char array

    //Now filter Even number and Odd number
    for (string x : cstr) {
        int z = stoi(x);
        if (z % 2 == 0) {
            EvenNo[EvenNumbering] += z;
            EvenNumbering++;
        }
        else {
            OddNo[OddNumbering] += z;
            OddNumbering++;
        }
    }
    cout &lt;&lt; endl;
    cout &lt;&lt; "Even Numbers: ";

    for (int x : EvenNo) {
        cout &lt;&lt; x &lt;&lt; ", ";
    }

    cout &lt;&lt; endl;
    cout &lt;&lt; "Odd Numbers: ";

    for (int x : OddNo) {
        cout &lt;&lt; x &lt;&lt; ", ";
    }

    system("pause");
    return 0;
}
</code></pre>

<p>My error: </p>

<pre><code>source.cpp(18): error C2131: expression did not evaluate to a constant
source.cpp(18): note: a non-constant (sub-)expression was encountered
source.cpp(19): error C2131: expression did not evaluate to a constant
source.cpp(19): note: a non-constant (sub-)expression was encountered
source.cpp(20): error C2131: expression did not evaluate to a constant
source.cpp(20): note: a non-constant (sub-)expression was encountered
source.cpp(26): error C2065: 'x': undeclared identifier
source.cpp(40): error C2065: 'x': undeclared identifier
source.cpp(47): error C2065: 'x': undeclared identifier
1&gt;Done building project "Question.vcxproj" -- FAILED.
</code></pre>

<p>Still new to C++ and this is my first Project so please forgive me if I did some beginner mistake.</p>
