Suppose if I need a two-dimensional array of characters, with the standard std :: basic_string I can create it as follows:

string **table = new string*[n]; for (int i = 0; i<n; i++){ table[i]=new string[n]; } 

How to implement the same with String ^? And how to format output, for example, in a textbox? I apologize for the stupid questions, asked the coursework, which needs to be done on windows forms. In the console I did everything, but with the windows there is a problem :(

    1 answer 1

    Do not write new string*[n]; in C ++. For such tasks there is a std::vector , and the correct code looks like this:

     std::vector<std::vector<std::string>> table(n); 

    In C ++ / CLI, this is rewritten 1 to 1: std::string is replaced by String^ , std::vector<> is replaced by array<>^ :

     auto table = gcnew array<array<String^>^>(n); 

    You do not need to use using namespace std; so that there is no conflict with std::array . However, in .NET, the tradition is to use using namespace System; .

    Also note that the type of the variable is a pointer to the array — array<T>^ , and we create the array itself — gcnew array<T>(n) (without ^ ).