如何用输入流类对象来判断存在文本文件中的纪录的维数

pixiu_lyf 2006-06-15 11:19:29
我的目的是选择文件之后,将此文本文件中的纪录读出,并显示在一个textbox中,同时判断此数据集的纪录数和维数。
我首先在打开菜单的click事件代码中实现文件的打开:
System::Void openFileMenu_Click(System::Object * sender, System::EventArgs * e)
{
OpenFileDialog *openFile = new OpenFileDialog;
Windows::Forms::DialogResult result = openFile->ShowDialog();
openFile->CheckFileExists = false;
if( result == DialogResult::Cancel )
return;
fileName = openFile->FileName;//fileName 是我在此类中定义的一个String*变量
showDatasetNamePathTextBox->Text = fileName;
printDataset( fileName );

}
然后我在printDataset( fileName )中实现:
void printDataset( String *thefileName )
{
outputTextBox->Clear();
patternNumTextBox->Clear();
int i=0;
try{
StreamReader *stream = new StreamReader( thefileName);
while( stream->Peek() >= 0){
outputTextBox->Text = String::Concat( outputTextBox->Text,
stream->ReadLine(), S"\r\n");
i++;//用i就可以判断数据集纪录的数目
}//end while
numPatterns = i;
stream->Close();
patternNumTextBox->Text = String::Concat( i.ToString());
}//end try
catch( IOException*){
MessageBox::Show( S"File Error", S"File Error",
MessageBoxButtons::OK, MessageBoxIcon::Error);
}//end catch
}//end method printDataset
但是,如何得到记录集的维数呢?
我考虑到将readLine读出的每一行记录保存到一个String*中,然后将它变成char[],然后判断数组中的空格或者tab键,如果有就计数。
可是没想到readLine 的返回值中不保存空格值。
怎么办?
我还能用什么办法?
在c++6.0中用getLine就可以判断空格,可是为什么在.net中的readLine就不可以呢?
由哪位大家可以帮助我?
...全文
103 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
pixiu_lyf 2006-06-17
  • 打赏
  • 举报
回复
自己顶一下

拜托那位前辈帮帮我呀!

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧