0
int N2 = N;
// 713
int length = to_string( N2 ).length();
// 3
int _NX = stoi( N2 );
// error std::stoi() requires a constant `std::string` reference as argument.
// Here an `int` was given.
// https://en.cppreference.com/w/cpp/string/basic_string/stol
// stoi() => `std::string` to `int`
0
N2 is still an integer.
to_string(N2) doesn't modify the original int N2
....
You can do your task like this
string str = to_string(N2);
int _NX = stoi(str);