Hi,I want to convert String^ to Int array or a char array.I am reading numbers from a file in GUI but the StreamReader Reads the Text in a String.I need to convert them to use the numbers.
I have tried ToCharArray() function but it doesnt work!

this function gives the following error:

e:\my documents\visual studio 2008\projects\assignment 3\assignment 3\Form1.h(109) : error C2440: 'initializing' : cannot convert from 'cli::array<Type,dimension> ^' to 'char []'
with
[
Type=wchar_t,
dimension=1
]

-------------------

Here is my code:

StreamReader ^read=gcnew StreamReader("matrice.txt");

				 String ^x=read->ReadLine();

				 char arr[]=x->ToCharArray();

				 MessageBox::Show(arr->ToString(),"message");

I need to convert the string to char or int array!
Thank You!

This might help, but I will caution you to remember that char and System::Char are not the same type. If you convert System::Char to char, there might be data loss depending on the contents of the string.

Return type of ToCharArray() is cli::array <wchar_t,1>.

String ^x=read->ReadLine();
    // String to char array
    array<Char>^ arr=x->ToCharArray();  

   // char arr to string
    String ^str=gcnew String(arr);
    Console::WriteLine(str);

Return type of ToCharArray() is cli::array <wchar_t,1>.

String ^x=read->ReadLine();
    // String to char array
    array<Char>^ arr=x->ToCharArray();  

   // char arr to string
    String ^str=gcnew String(arr);
    Console::WriteLine(str);

i havent used that array.
how can i use the elements of the array?

if i have an array char x[]={"whaterver"};

then i know that x[0] has 'w' in it.

how do i know the same thing in the array you have mentioned?

Thanks

This article has been dead for over six months. Start a new discussion instead.