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