UpdateData(true);
CFile file;
CFileException e;
if(file.Open(_T("cc.txt"),CFile::modeCreate | CFile::modeNoInherit | CFile::modeReadWrite,&e))
{
DWORD byte = file.GetLength();
char * buf;
file.Read(buf,byte);
for(int i=0;i<byte;i++)
m_str = m_str+buf[i];
file.Close();
UpdateData(false);
AfxMessageBox(_T("读文件成功!"));
}
else
{
afxDump << "File could not be opened"<<e.m_cause<<"\n";
}m_str 是一个Edit控件的CString 变量
不知道为什么总是读不出来,而且每次我单步执行时候byte总是0
可是我文件里确实有数据。
在线等待
CFile file;
CFileException e;
if(file.Open(_T("cc.txt"),CFile::modeCreate | CFile::modeNoInherit | CFile::modeReadWrite,&e))
{
DWORD byte = file.GetLength();
char * buf;
file.Read(buf,byte);
for(int i=0;i<byte;i++)
m_str = m_str+buf[i];
file.Close();
UpdateData(false);
AfxMessageBox(_T("读文件成功!"));
}
else
{
afxDump << "File could not be opened"<<e.m_cause<<"\n";
}m_str 是一个Edit控件的CString 变量
不知道为什么总是读不出来,而且每次我单步执行时候byte总是0
可是我文件里确实有数据。
在线等待
解决方案 »
- 关于俄罗斯方块的几个问题
- VC中添加类的方法有二种有何区别
- 最基础的VC问题
- 求OpenGL 1.4或者1.5,2.0版本的的gl.h, glu.h, opengl32.lib, glu32.lib文件,还有新版本的glext.h
- 线程中怎么调用UpdateData()?
- [书摘] Microsoft Windows Server 2003 TCP/IP 协议和服务技术参考 之 ARP (1)
- 关于CRectTracker的一个小问题1行代码,帮忙。。
- 有关《windows网络编程》的例程问题
- 是什么对话框?
- 控制滚动条滑动
- 请帮忙:如何实现OpenGL和普通GDI图形的同时显示?谢谢!
- 一个文挡对应多个VIEW
代替char *buf
buf = new char[byte]delete buf; //在这个函数内释放堆内存。
buf = (char *)malloc(1024);或char buf[1024]
//这样可以避免读到乱码,因为你没指定存储位置
DWORD byte = file.GetLength();char * buf = new char[ (int)byte ];//申请适合大小的内存空间
……delete buf;//事情完了后不要忘记要释放内存
……delete buf;//事情完了后不要忘记要释放内存