读书人

vs2008 clr程式 int string解

发布时间: 2012-02-09 18:22:27 作者: rapoo

vs2008 clr程式 int string
vs2008 clr程式 int string

IO::StreamReader^ sr = File::OpenText(L"G:\\006.txt");
richTextBox1->Text = sr->Read();

Read()返回的是int32,不知道怎richTextBox1示出。

[解决办法]
read一次读取一个字符,强制转化成Char

C/C++ code
using namespace System;using namespace System::IO;int main(){   String^ path = "c:\\temp\\MyTest.txt";   try   {      if ( File::Exists( path ) )      {         File::Delete( path );      }      StreamWriter^ sw = gcnew StreamWriter( path );      try      {         sw->WriteLine( "This" );         sw->WriteLine( "is some text" );         sw->WriteLine( "to test" );         sw->WriteLine( "Reading" );      }      finally      {         delete sw;      }      StreamReader^ sr = gcnew StreamReader( path );      try      {         while ( sr->Peek() >= 0 )         {            Console::Write( (Char)sr->Read() );         }      }      finally      {         delete sr;      }   }   catch ( Exception^ e )    {      Console::WriteLine( "The process failed: {0}", e );   }} 

读书人网 >VC

热点推荐