What does binary stream mean?

anrxhzh 2002-05-30 11:51:23
#include <fstream>
#include <iterator>
#include <algorithm>
#include <iostream>

void main()
{
using namespace std;
copy( istream_iterator<char>( ifstream("sample.txt",ios_base::in | ios_base::binary) ),
istream_iterator<char>(),
ostream_iterator<char>( cout ) );
}
//为什么把换行符过滤掉了?

//sample.txt
//hello
//world

//output:
//helloworld
...全文
113 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
alula 2002-07-14
  • 打赏
  • 举报
回复
原来如此!

吃饭去。
Juventus 2002-07-14
  • 打赏
  • 举报
回复
捧场来了!!
anrxhzh 2002-07-14
  • 打赏
  • 举报
回复
这个帖子是自问自答,如果一下子给别人几十分,有失公允。
alula 2002-07-14
  • 打赏
  • 举报
回复
一定要捧场才可以结贴吗?
anrxhzh 2002-07-14
  • 打赏
  • 举报
回复
乡亲们捧个场,俺准备散分了。
anrxhzh 2002-07-13
  • 打赏
  • 举报
回复
noskipws is a manipulators.
关于 manipulators 的概念,请看:
http://www.dinkumware.com./htm_cpl/ios.html

skipws skip leading white space before certain extractions.
关于 white space 的概念,请看:
http://www.dinkumware.com./htm_cpl/ctype.html#isspace
lizsss 2002-07-12
  • 打赏
  • 举报
回复
dev-c++ 5.0 结果正确!
麻烦说一下:istream_iterator<char>( ifstream("sample.txt",ios_base::in | ios_base::binary)>>noskipws ),
其中的"noskipws"以及">>"什么意思???
anrxhzh 2002-07-12
  • 打赏
  • 举报
回复
哪位好心人顶一下,让俺把这个帖子结了。多谢了。
zheng_can 2002-05-30
  • 打赏
  • 举报
回复
我记得可以设置 istream 的状态
方法与 setw() 类似
你去查查书看
anrxhzh 2002-05-30
  • 打赏
  • 举报
回复
//我受调试结果的启发,终于搞定了。不过,真不知道说什么好,哎!
#include <fstream>
#include <iterator>
#include <algorithm>
#include <iostream>
#include <iomanip>

void main()
{
using namespace std;
copy( istream_iterator<char>( ifstream("sample.txt",ios_base::in | ios_base::binary)>>noskipws ),
istream_iterator<char>(),
ostream_iterator<char>( cout ) );
}
//the contents of sample.txt
//hello
//world

//output:
//hello
//world
anrxhzh 2002-05-30
  • 打赏
  • 举报
回复
你指的是setiosflags吧,我试了一下,没有用。

我跟踪了一下,在<istream>中的这条语句_Fac.is(_Ctype::space,_Tr::to_char_type(_C))把换行符过滤掉了。
bool ipfx(bool _Noskip = false)
{if (good())
{if (tie() != 0)
tie()->flush();
if (!_Noskip && flags() & skipws)
{const _Ctype& _Fac = _USE(getloc(), _Ctype);
_TRY_IO_BEGIN
int_type _C = rdbuf()->sgetc();
while (!_Tr::eq_int_type(_Tr::eof(), _C)
&& _Fac.is(_Ctype::space,
_Tr::to_char_type(_C)))
_C = rdbuf()->snextc();
_CATCH_IO_END }
if (good())
return (true); }
setstate(failbit);
return (false); }

"The actual values of openmodes and their meanings are implementation-defined." -TCPL 21.5.1
November 1997 Draft Standard 中对此也没有提及。
依然不解。
我是在VC6.0下测试的,我用IBM VisualAge和Cygwin gcc都编译不过,有条件的朋友用其他编译器试试吧。

70,023

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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