//--------------------------------------------------------------------------- #include <vcl.h> #include <iostream.h> #include <fstream> #include <string> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { this->OpenDialog1->FileName ="*.inp"; this->OpenDialog1->Title="打开lxly.inp文件"; if(this->OpenDialog1->Execute()) { string str,str1,str2,str3,str4,str5,str6,str7; ifstream inf(this->OpenDialog1->FileName.c_str()); for(int i=1;i<=4;i++) { getline(inf,str); this->CheckListBox1->Items->Add(str.c_str()); } this->ProgressBar1->Min =5; this->ProgressBar1->Max =83650; int k=5; TStringList *ttt=NULL; ttt=new TStringList(); while(!inf.eof()) { inf>>str1>>str2>>str3>>str4>>str5>>str6>>str7; this->CheckListBox1->Items->Add((str1+" "+str2).c_str()); ttt->Add((str1+" "+str2).c_str()); k++; this->ProgressBar1->Position=k; } this->CheckListBox1->Items =ttt; inf.close(); } } //---------------------------------------------------------------------------
以上代码在C++builder 6下可以编译通过,且有效,但在C++Builder XE4下也可以编译通过,但无效,即在checklistbox中没有数据出现。
请告诉原因,并告诉如何改正,(注:不要用Memo等控件直接读取原文件)
没有人知道,关贴了。