怎样读入一个文本文件,使我能够按字符来处理它

cpp_pro 2002-11-24 03:39:39
同上

是不是得到文件的首地址?
我这样做了,可是老是出错误。

说什么那个地址是只读的。
怎么回事?
...全文
40 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
copy_paste 2002-11-27
  • 打赏
  • 举报
回复
老兄,我少打了一个"}"在__finally前面。
cpp_pro 2002-11-27
  • 打赏
  • 举报
回复
to copy_paste(木石三) :

有错误啊:(
borland_boy 2002-11-24
  • 打赏
  • 举报
回复
#include <stdio.h>
FILE *fp;
char salelist;
if((fp=fopen(path1.c_str(),"rb"))==NULL)
return 100; //文件未找到
fseek(fp,0,0);
for(i=0; i<l; i++ ){
if( fread( &salelist, sizeof(salelist_type), 1, fp)!=1){
return -1;//读错误
}
fclose(fp);
copy_paste 2002-11-24
  • 打赏
  • 举报
回复
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if (!OpenDialog1->Execute()) return;
TFileStream *Stream = new TFileStream(OpenDialog1->FileName, fmShareDenyNone);
try
{
AnsiString Source = EmptyStr;
int Count = Stream->Size;
Source.SetLength(Count);
Stream->ReadBuffer(Source.c_str(), Count);
// 使用 Source
Source.SetLength(0);
__finally
{
delete Stream;
}
}
sjd163 2002-11-24
  • 打赏
  • 举报
回复
你要注意,汉字占两的字节。要有对汉字的判断,
是汉字的成对的提取。
wangxin_qaz 2002-11-24
  • 打赏
  • 举报
回复
Sorry,I can't write in Chinese,but my English is poor......There is a little problems in my computer.

First,use the function of FileOpen to open the text file.

Second ,use FileRead function to read file content into a buffer,then you can deal with the buffer....

In the end,use the function of FileClose to close the file......(you may open the file ,but don't close the file in the program early......the problem is here?)

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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