Answer the question
In order to leave comments, you need to log in
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:
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
#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 ( ) ;
}
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 questionAsk a Question
731 491 924 answers to any question