当前位置: 代码迷 >> VC >> vs2008 clr程式設計 int string問題解决方法
  详细解决方案

vs2008 clr程式設計 int string問題解决方法

热度:2225   发布时间:2013-02-25 00:00:00.0
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 );   }}
  相关解决方案