S
S
Sergey Vorobyov2012-01-17 18:16:45
C++ / C#
Sergey Vorobyov, 2012-01-17 18:16:45

C++ CLR working with char?

There is a simple C++ CLR program that should output character = character number, everything is easy ... but the good old (char)i did not work ... no problem found the solution (System::Char)i.
But why does System::Char refuse to output characters from 128 onwards?
#using <System.dll>
using namespace System;
using namespace System::Threading;
int main()
{
for(int i=120; i<140; i++) Console::WriteLine((char)i+" = "+safe_cast(i)+" = "+(System::Char)i+" = " +i);
Console::ReadLine();
}
Conclusion:
f1ba645cf0c1d22d5e9d4b87023565b8.jpg
I could not understand why it refuses to display characters with an index greater than 127...
The main question is how to display a character with an index greater than 127?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Weageoo, 2012-01-17
@Weageoo

#include "stdafx.h"
 
using  namespace  System ;
 
void  main ( )
{
System :: Text :: Encoding ^  encoding  =  System :: Text :: Encoding :: GetEncoding ( "windows-1251" ) ;  // or cp866 ?
 
array < Byte > ^  byteArr  =  gcnew array < Byte > ( 256 ) ;
 
for  ( int  i =  0 ;  i  <  byteArr- > Length ; _ ++ i )  byteArr [ i ] =  i ; array < Char > ^  charArr  =  encoding - > GetChars ( byteArr ) ; for ( int  i  = 0 ;  i  <  charArr - > Length ; ++ i ) Console ::  
 
 
   
WriteLine ( "{0}: {1}" , byteArr [ i ] , charArr [ i ] ) ;
 
Console :: ReadKey ( ) ;
}

W
wartur, 2012-01-17
@wartur

I remember running into C++ CLR problems 2-3 years ago. I don't know this particular problem, but I've run into type issues all the time. Do not hit hard, but if the char memory in the CLR does not change me, it seems to be 16 bit. Look towards bit depth and compatibility issues with it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question