0

Haven't found an answer anywhere on how to convert a string array to int array.

for (int m=0; m<z; m++)
{
    rikiavimas(rekordininkai[m], i);
}

private: void rikiavimas(array<Int32>^ A, int j)
{
    A = gcnew array<Int32>(100);
}

My rekordininkai[m] is a string array. How can I get this to work?

Gitdown
  • 13
  • 5
  • What do you mean by converting a string array to int array? Are all thw strings in the string array integers? – Banach Tarski Mar 28 '16 at 10:31
  • Yes, all of them are integers. – Gitdown Mar 28 '16 at 10:39
  • Ugh, you did not get very far. The `A` parameter should of course be an array of strings. Use A->Length instead of 100. Use Int32::Parse() to convert from a string to an int. What the `j` parameter might mean is very hard to guess. My crystal ball says that rekordininkai[m] is a string, not a string array. – Hans Passant Mar 28 '16 at 10:53

1 Answers1

0
const int N = 100; // just an example

string arrayOfStrings[N];
int arrayOfIntegers[N];

for(int i = 0; i < N; i++) cin >> arrayOfStrings[i];

for(int i = 0; i < N; i++) arrayOfIntegers[i] = stoi(arrayOfStrings[i]);

You can read the documentation for stoi for more details.

Also see this for additional methods.

Community
  • 1
  • 1
Banach Tarski
  • 1,821
  • 17
  • 36