下面BCB帮助中的newchar[]是自定义的吗?

Persistent8813 2006-11-29 09:57:29
The following example uses a button, a string grid, and an Open dialog box on a form. When the button is clicked, the user is prompted for a filename. When the user clicks OK, the specified file is opened, read into a buffer, and closed. Then the buffer is displayed in two columns of the string grid. The first column contains the character values in the buffer. The second column contains the numeric values of the characters in the buffer.

void __fastcall TForm1::Button1Click(TObject *Sender)

{
int iFileHandle;
int iFileLength;
int iBytesRead;
char *pszBuffer;
if (OpenDialog1->Execute())
{
try
{
iFileHandle = FileOpen(OpenDialog1->FileName, fmOpenRead);
iFileLength = FileSeek(iFileHandle,0,2);
FileSeek(iFileHandle,0,0);

pszBuffer = newchar[iFileLength+1]; // 这个~~

iBytesRead = FileRead(iFileHandle, pszBuffer, iFileLength);
FileClose(iFileHandle);

for (int i=0;i<iBytesRead;i++)
{
StringGrid1->RowCount += 1;
StringGrid1->Cells[1][i+1] = pszBuffer[i];
StringGrid1->Cells[2][i+1] = IntToStr((int)pszBuffer[i]);
}
delete [] pszBuffer;
}
catch(...)
{
Application->MessageBox("Can't perform one of the following file operations: Open, Seek, Read, Close.", "File Error", IDOK);
}
}
}
...全文
102 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Persistent8813 2006-11-29
  • 打赏
  • 举报
回复
K,原来,也没想想,只看到是黑体显示就~
我不懂电脑 2006-11-29
  • 打赏
  • 举报
回复
pszBuffer = new char[iFileLength+1]; // 这个~~
wangxintu 2006-11-29
  • 打赏
  • 举报
回复
哈哈
samchoy 2006-11-29
  • 打赏
  • 举报
回复
同意楼上的,应该是少了个空格
cczlp 2006-11-29
  • 打赏
  • 举报
回复
文档写错了, 应该是 pszBuffer = new char[iFileLength+1];

1,221

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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