我想在记事本里输出一个CPoint p[100]的横纵坐标。怎么输出。我这么做
CString str1;
CString str2;
CFile file;
for(int i=0;i<100;i++)
{
str1.Format("%d", p[i].x);
str2.Format("%d", p[i].x);
file.Open("abc.txt", CFile::modeCreate|CFile::modeWrite);
file.Write(str1.GetBuffer(0), str1.GetLength());
file.Write(str2.GetBuffer(0), str2.GetLength());
}
file.Close();
编译显示有错误。请问怎么办啊,请各位大侠帮忙。
CString str1;
CString str2;
CFile file;
for(int i=0;i<100;i++)
{
str1.Format("%d", p[i].x);
str2.Format("%d", p[i].x);
file.Open("abc.txt", CFile::modeCreate|CFile::modeWrite);
file.Write(str1.GetBuffer(0), str1.GetLength());
file.Write(str2.GetBuffer(0), str2.GetLength());
}
file.Close();
编译显示有错误。请问怎么办啊,请各位大侠帮忙。
解决方案 »
- VS2010 真彩色工具栏
- 在VC将ACCESS导出为文本的问题
- 对话框程序,改变了背景颜色再改变了EDIT控件颜色,但EDIT控件的白色边(3D边框)不知如何改颜色?
- 问ActiveX控件中的事件,是否属于线程的一种??
- 哈哈,需要短信网关IP地址及其源代码的快来顶一下。
- 熟悉directdraw的进来
- 真怪,为什么我的 virtual 有时候能运行不时候则不能?
- Smtp服务器的一个问题。好苦恼。
- 网页接收ocx事件返回的字符串丢失一位
- 我按照MSDN的步骤....但还是不行,是不是我的VC 或WINDOWS 有问题了?(关于ACITVEX CONTRCOL)
- 怎么标识线程?
- 能不能写一个简单的Select模型的网络程序,客户端和服务器都是本机?
file.Open("abc.txt", CFile::modeCreate|CFile::modeWrite);// 在使用之前先打开
for(int i=0;i<100;i++)
{
str1.Format("%d", p[i].x);
str2.Format("%d", p[i].x);
file.Write(str1.GetBuffer(0), str1.GetLength());
file.Write(str2.GetBuffer(0), str2.GetLength());
}
file.Close();
void CFileWriteDlg::OnButton1()
{
CFile mWriteFile;
mWriteFile.Open("c:\\IcInfo.txt",CFile::modeCreate| CFile::modeWrite);
CArchive ar(&mWriteFile,CArchive::store);////////////////////////
ar<<CPoint(12,34);
/////////////////////// ar.Close();
mWriteFile.Close();
}Read from file
void CFileWriteDlg::OnButton2()
{
CFile mWriteFile;
mWriteFile.Open("c:\\IcInfo.txt",CFile::modeRead);
CArchive ar(&mWriteFile,CArchive::load);////////////////////////
CPoint pt;
ar>>pt;
CString s;
s.Format("%d-%d",pt.x,pt.y);
MessageBox(s);
/////////////////////// ar.Close();
mWriteFile.Close();
}
放循环外,你这样还没关闭就又打开文件,当然会出错了
str1.Format("%d ", p[i].x);
str2.Format("%d ", p[i].x); //这里你写错了,应该是p[i].y
str1.Format("%d \r\n", p[i].x);
str2.Format("%d \r\n", p[i].x); //这里你写错了,应该是p[i].y
放在循环外面,结束时要Close()