文件内容如下:
C DXDY.INP FILE, IN FREE FORMAT ACROSS COLUMNS for 83658 Active Cells
C 2013-5-25 上午 10:43:53
C BOTTOM Veg
C I J DX DY DEPTH ELEV ZROUGH TYPE
3 143 221.500 187.900 0.090 22.000 0.0200
3 144 222.000 188.100 0.090 22.000 0.0200
3 145 222.200 188.100 0.090 22.000 0.0200
4 143 223.100 187.900 0.090 22.000 0.0200
4 144 223.300 187.900 0.090 22.000 0.0200
4 145 223.500 187.800 0.090 22.000 0.0200
5 142 222.400 187.900 0.090 22.000 0.0200
5 143 222.500 187.900 0.090 22.000 0.0200
5 144 222.700 187.800 0.090 22.000 0.0200
6 140 222.300 188.600 0.090 21.154 0.0200
6 141 222.500 188.700 0.090 22.000 0.0200
6 142 222.800 187.900 0.090 22.000 0.0200
6 143 222.900 187.800 0.090 22.000 0.0200
...........
文件共83650行,采用以下方式读取,并将读取的每行头两个变量显示在CheckListBox中:
//--------------------------------------------------------------------------- #include <vcl.h>
#include <fstream.h>
#include <string.h>
#pragma hdrstop #include "readlxly.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=;i<=;i++)
{
getline(inf,str);
this->CheckListBox1->Items->Add(str.c_str());
}
this->ProgressBar1->Min =;
this->ProgressBar1->Max =;
int k=;
TStringList *ttt=NULL;
ttt=new TStringList(); while(!inf.eof())
{
inf>>str1>>str2>>str3>>str4>>str5>>str6>>str7;
ttt->Add((str1+" "+str2).c_str());
k++;
this->ProgressBar1->Position=k;
}
this->CheckListBox1->Items =ttt;
inf.close();
}
}
//---------------------------------------------------------------------------