简单的ifstream问题 [英] Simple ifstream question
问题描述
好的,这很简单,但我不能认为什么是最好的
和最优雅的解决方案。
说我得到了一个int来自ifstream如下:
int val;
inFile.get(reinterpret_cast< char *>(& val),sizeof(val)) ;
如何知道这是否成功?它只返回false,如果
eof在int的末尾。
OK this is really simple but I can''t think what is the best
and most elegant solution.
Say I am getting an int from an ifstream as follows:
int val;
inFile.get(reinterpret_cast<char*>(&val), sizeof(val));
How do I know if this succeeded? It only returns false if
the eof is at the end of the int.
推荐答案
翻转 < FL *** @ flops.comm>在消息中写道
news:bp ********** @ news.freedom2surf.net ...
"flips" <fl***@flops.comm> wrote in message
news:bp**********@news.freedom2surf.net...
好的,这很简单,但我可以'我认为什么是最好的
和最优雅的解决方案。
说我从ifstream获得一个int如下:
int val;
inFile.get(reinterpret_cast< char *>(& val),sizeof(val));
我怎么知道这是否成功?如果eof位于int的末尾,它只返回false。
OK this is really simple but I can''t think what is the best
and most elegant solution.
Say I am getting an int from an ifstream as follows:
int val;
inFile.get(reinterpret_cast<char*>(&val), sizeof(val));
How do I know if this succeeded? It only returns false if
the eof is at the end of the int.
if(!inFile&&!inFile.eof())
/ *错误* /
-Mike
if(!inFile && !inFile.eof())
/* error */
-Mike
你生气了吗?
" Mike Wahler" < MK ****** @ mkwahler.net>在消息中写道
新闻:eA ****************** @ newsread1.news.pas.earth link.net ...
Are you mad?
"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:eA******************@newsread1.news.pas.earth link.net...
翻转 < FL *** @ flops.comm>在消息中写道
新闻:bp ********** @ news.freedom2surf.net ...
"flips" <fl***@flops.comm> wrote in message
news:bp**********@news.freedom2surf.net...
好的,这很简单,但我不能想到是什么是最好的
和最优雅的解决方案。
说我从ifstream获取一个int如下:
int val;
inFile.get (reinterpret_cast< char *>(& val),sizeof(val));
我如何知道这是否成功?如果eof位于int的末尾,它只返回false。
OK this is really simple but I can''t think what is the best
and most elegant solution.
Say I am getting an int from an ifstream as follows:
int val;
inFile.get(reinterpret_cast<char*>(&val), sizeof(val));
How do I know if this succeeded? It only returns false if
the eof is at the end of the int.
if(!inFile&&!inFile.eof())
/ *错误* /
-Mike
if(!inFile && !inFile.eof())
/* error */
-Mike
"翻转" < FL *** @ flops.comm>在消息中写道
news:bp ********** @ news.freedom2surf.net ...
"flips" <fl***@flops.comm> wrote in message
news:bp**********@news.freedom2surf.net...
你疯了吗?
完全没有。如果我写的东西没有用,
或许你应该更清楚地表达你的问题
。
BTW请不要顶级帖子。
-Mike
Not at all. If what I wrote doesn''t help,
perhaps you should express your problem more
clearly.
BTW Please don''t top post.
-Mike
这篇关于简单的ifstream问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!