程序是在本地拷贝文件。void CFileDlg::OnButton1()
{
// TODO: Add your control notification handler code here
const int size = 512;
char * buf;
CString s;
UpdateData();
CFile file,file1;
file1.Open((LPCTSTR) m_edit2, CFile::modeCreate | CFile::modeWrite);
if (file.Open((LPCTSTR) m_edit1, CFile::modeRead))
{
int length = file.GetLength();
int uBytesRead = 0;
int total = 0;
for (; total != length; )
{
buf = new char[size];
uBytesRead = file.Read(buf,size);
total += uBytesRead;
buf[uBytesRead] = '\0';
file1.Write(buf, uBytesRead);
delete[] buf;// 这里有错
}
file1.Close();
file.Close();
}
else AfxMessageBox("No file found!");}
{
// TODO: Add your control notification handler code here
const int size = 512;
char * buf;
CString s;
UpdateData();
CFile file,file1;
file1.Open((LPCTSTR) m_edit2, CFile::modeCreate | CFile::modeWrite);
if (file.Open((LPCTSTR) m_edit1, CFile::modeRead))
{
int length = file.GetLength();
int uBytesRead = 0;
int total = 0;
for (; total != length; )
{
buf = new char[size];
uBytesRead = file.Read(buf,size);
total += uBytesRead;
buf[uBytesRead] = '\0';
file1.Write(buf, uBytesRead);
delete[] buf;// 这里有错
}
file1.Close();
file.Close();
}
else AfxMessageBox("No file found!");}
解决方案 »
- 想用Word2007的RibbonComboBox/RibbonDropDown等类,不知道要#import那个类型库或者DLL
- 字符整数转换函数
- GetProcAddress返回不正常!老是为0
- 我被封了???给个理由吧
- 我在STRING TABLE里面定了一些串,但是用的时候弹出异常:ASSERT(afxCurrentResourceHandle != NULL)
- VC++的最高版本是几?
- 如何用VC编程实现将avi文件转换成流媒体格式的(mpg/asf等任意一种)文件?
- 请教一个ClistCtrl问题?
- 请教一个关于运行响应消息的问题
- 用SHBrowseForFolder生成的可选择路径的对话框,想改变其中的编辑框,请大侠指点
- 怎样将自己的机器设置为ftp服务器
- 请问BS和CS的特点和区别!
void CFileDlg::OnButton1()
{
// TODO: Add your control notification handler code here
const int size = 512;
char * buf;
CString s;
UpdateData();
CFile file,file1;
file1.Open((LPCTSTR) m_edit2, CFile::modeCreate | CFile::modeWrite);
if (file.Open((LPCTSTR) m_edit1, CFile::modeRead))
{
int length = file.GetLength();
int uBytesRead = 0;
int total = 0;
buf = new char[size]; for (; total != length; )
{
uBytesRead = file.Read(buf,size);
total += uBytesRead;
buf[uBytesRead] = '\0';
file1.Write(buf, uBytesRead);
}
delete[] buf;
file1.Close();
file.Close();
}
else AfxMessageBox("No file found!");}因为VC在实现方面和标准C++有区别。
hSFile = fopen("123.Text", "rt");
if (hSFile == NULL)
return;
hDFile = fopen("12354.Txt", "w+t");
if (hDFile == NULL)
{
fclose(hSFile);
return;
}
LONG nLength = _filelength(_fileno(hSFile));byte *buf = new byte[nLength];
if (buf == NULL)
{
fclose(hSFile);
fclose(hDFile);
}fread(buf, 1, nLength, hSFile);
fclose(hSFile);
fwrite(buf, 1, nLength, hDFile);
fclose(hDFile);
if (buf == NULL)
{
fclose(hSFile);
fclose(hDFile);
}fread(buf, 1, nLength, hSFile);
fclose(hSFile);
fwrite(buf, 1, nLength, hDFile);
fclose(hDFile);
//////
delete []buf;