首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VC >

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

2012-02-09 
vs2008 clr程式設計 int string問題vs2008 clr程式設計 int string問題IO::StreamReader^ sr File::Open

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 );   }} 

热点排行