L
L
Lisik2020-11-26 16:41:47
C++ / C#
Lisik, 2020-11-26 16:41:47

How to fill an array in C++/CLI?

I've just started learning C++/CLI, so I don't fully understand the input methods.
Let's say I create an array. How can I fill it out? The code below fills an array with obscure values.

#include "pch.h"

using namespace System;

int main(array<System::String ^> ^args)
{
    array<int>^ M = gcnew array <int>(7);
    Console::Write(L"Массив М(7): ");
    for (int i = 0; i < M->Length; i++)
    {
        M[i] = Convert::ToInt32(Console::Read());
    }
    for (int i = 0; i < 7; i++)
        Console::Write(L"{0} ", M[i]);
    return 0;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2020-11-26
@Lisik

try Console::ReadLine() and int::TryParse

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question