新人求解

yue_tq 2012-10-26 09:47:35
我有如下结构体:
typedef struct Point
{
int w;
CPoint point_begin;
CPoint point_end;
}Point;
typedef std::vector<Point> ar_point;
ar_point m_point;

存入一个文件中。用的如下函数:
void CDrawView::SaveFile(CString filename)
{
ofstream ofs(filename,ios::binary);
INT i = 0;
for(std::vector<Point>::iterator it = m_point.begin();it != m_point.end();it++)
{
ofs.write((char*)&m_point[i],sizeof(m_point));
i++;
}
ofs.close();
}
但是我在读取该文件的时候出现了编译的错误?
求教如何更改?
void CDrawView::LoadFile(CString filename)
{
ifstream ifs(filename);
Point m(0);
while(ifs.read((char*)&m,sizeof(Point)) > 0)
m_point.push_back(m);
ifs.close();
}
error C2146: syntax error : missing ';' before identifier 'm'
error C2065: 'm' : undeclared identifier
error C2678: binary '>' : no operator defined which takes a left-hand operand of type 'class std::basic_istream<char,struct std::char_traits<char> >' (or there is no accep
table conversion)
fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.
Creating browse info file...
BSCMAKE: error BK1506 : cannot open file '.\Debug\drawView.sbr': No such file or directory
Error executing bscmake.exe.
...全文
277 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
buyong 2012-10-26
  • 打赏
  • 举报
回复
你这不是在胡写么?
你的 ar_point m(0);你想干什么,把m变成一个容器?
[Quote=引用 5 楼 的回复:]

void CDrawView::LoadFile(CString filename)
{
ifstream ifs(filename);
ar_point m(0);
while(ifs.read((char*)&m,sizeof(ar_point)) > 0)
m_point.push_back(m);
ifs.close();
}
我更改了一下,还……
[/Quote]
yue_tq 2012-10-26
  • 打赏
  • 举报
回复
void CDrawView::LoadFile(CString filename)
{
ifstream ifs(filename);
ar_point m(0);
while(ifs.read((char*)&m,sizeof(ar_point)) > 0)
m_point.push_back(m);
ifs.close();
}
我更改了一下,还有3个错误了(楼顶错误从下往上数3个),还应该怎么更改?
yue_tq 2012-10-26
  • 打赏
  • 举报
回复
#2楼的方法不好使啊,能不能求教一个方法啊?这七嘴八舌的,我都搞懵了。
十八道胡同 2012-10-26
  • 打赏
  • 举报
回复
error C2678: binary '>' : no operator defined which takes a left-hand operand of type 'class std::basic_istream<char,struct std::char_traits<char> >' (or there is no accep
table conversion)

意思是while(ifs.read((char*)&m,sizeof(Point)) > 0) read的返回值没办法和0进行比较

read的返回值应该是class std::basic_istream<char,struct std::char_traits<char> >,是个stream
冰与火 2012-10-26
  • 打赏
  • 举报
回复
typedef struct Point
{
int w;
CPoint point_begin;
CPoint point_end;
}Point;你先把这个两个Point换成不同的标识符。
再看有问题吗
ouyh12345 2012-10-26
  • 打赏
  • 举报
回复
typedef struct tagPoint
{
int w;
CPoint point_begin;
CPoint point_end;
}Point;

ifstream::read返回值是什么?
zjs100901 2012-10-26
  • 打赏
  • 举报
回复
请点图片
[img=http://img.wallba.com/ImagesCache/750x750max/data/ImageKankan/wallpaper/02e8cf42/201206/1fd74861b2634fdd2d72d8ca6a6a2ac0.jpg]http://topic.csdn.net/u/20121026/13/7fc45192-a0e8-4ceb-9d31-3ca738a29e49.html?seed=1636525172&r=80002226#r_80002226[/img]

65,183

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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