输入输出流 [英] IOStreams

查看:84
本文介绍了输入输出流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有两种方法可以从流中捕获''line''(附带

streambuf,从套接字读取/写入)。

一个是std函数getline另一个是getline

流本身的方法。愚蠢的流只有一个char_type缓冲区,当

''std :: getline()''采用真正的字符串引用时!

我更喜欢带有basic_string的那个REF。这是'

这种方法的困境,我不知道如何测试EOF。 :(使用iostreams

getline方法,它会返回''0'或EOF上的那种效果。请

建议!:P

这与IOStreams本身有点不太相关,但是因为我已经在同一个环境中遇到了这个问题,我希望这至少会超过

midly好吧。

这是一个只在Windows平台上发生的问题(尝试

不要把这看作是Windows特定的问题 - 我是试图理解用于C语言的C ++技术。)。我想知道一个C ++程序员接受了

删除尾随''\ r''的方法从其中一个getline

格式的结果。我不想假设''\ r''在那里,所以我会感激一些

选项。我听说如果我在文本模式下打开流,它应该由

平台的CRT处理。我只看到二进制模式

流的设置。


我还在使用标准C ++ IOStreams和Locales。所以也许

答案就在那里。我还是会感激任何指示。


ty~

解决方案



< ye ** @ twenty.net>在消息新闻中写道:sMd_c.65977


S55.51216@clgrps12 ...

有两种方法可以从流中查找'行' (附带
streambuf,从套接字读取/写入)。
一个是std函数getline另一个是getline流本身的方法。愚蠢的流只有一个char_type缓冲区,当
''std :: getline()''采用真正的字符串引用!


我认为这是因为iostream比字符串旧。

我更喜欢带有basic_string ref的那个。这是这种方法的困境,我不知道如何测试EOF。 :(使用iostreams
getline方法,它返回''0''或者EOF上的那些东西。请
建议!:P


同样的回报两种情况。

这与IOStreams本身有点不太相关,但是因为我已经在同一个环境中遇到了这个问题,所以我希望这至少可以解决这个问题。
这是一个只在Windows平台上发生的问题
(尝试不要将此视为Windows特定问题 - 我正在努力
理解用于C语言的C ++技术。)。我想知道一个C ++程序员
接受了从其中一个结果中删除尾随''\ r''的方法getline
格式。我不想假设''\ r''在那里,所以我会欣赏一些
选项。我听说它应该是如果我在文本模式下打开流,则由
平台的CRT处理。我只看到二进制模式
s ett for the stream。




如果您不打开二进制模式,那么您将以文本模式打开。 IOW text

模式是默认模式。如果你想确定一些简单的字符串

操作可以查找并删除尾随的''\ r''。我认为没有任何特别接受的方法可以做到这一点。


john


< blockquote>文章< sMd_c.65977


There are two methods of snagging a ''line'' from a stream (with an attached
streambuf that reads/writes from a socket).
One is the std function "getline" and the other is the "getline" method of
the stream itself. Silly the stream only takes a char_type buffer when the
''std::getline()'' takes a bonafide string reference!
I prefer the one that takes the basic_string ref. Here''s the dilema with
this approach, I don''t know how to test for EOF. :(Using the iostreams
getline method it returns ''0'' or something to that effect on EOF. Please
advise! :P

This is a little less related to IOStreams themselves but since I''ve
encountered this within the same context I hope this goes over at least
midly well.
This is a problem that is only happening to me on the Windows platform (try
not to think of this as a Windows specific issue -- I''m trying to understand
C++ techniques for C practices.). I''d like to know a C++ programmer accepted
way of removing the trailing ''\r'' from the result of one of the getline
formats. I don''t want to assume the ''\r'' is there so I''d appreciate some
options. I have heard that it''s supposed to be handled by the CRT of the
platform if I open the stream in text mode. Well I see only a binary mode
setting for the stream.

I''m still working through "Standard C++ IOStreams and Locales" so perhaps
the answers are there. I''d still appreciate any pointers.

ty~

解决方案


<ye**@twenty.net> wrote in message news:sMd_c.65977


S55.51216@clgrps12...

There are two methods of snagging a ''line'' from a stream (with an attached
streambuf that reads/writes from a socket).
One is the std function "getline" and the other is the "getline" method of
the stream itself. Silly the stream only takes a char_type buffer when the
''std::getline()'' takes a bonafide string reference!
I think this is because iostream is older than string.
I prefer the one that takes the basic_string ref. Here''s the dilema with
this approach, I don''t know how to test for EOF. :(Using the iostreams
getline method it returns ''0'' or something to that effect on EOF. Please
advise! :P
Same return for both cases.

This is a little less related to IOStreams themselves but since I''ve
encountered this within the same context I hope this goes over at least
midly well.
This is a problem that is only happening to me on the Windows platform
(try
not to think of this as a Windows specific issue -- I''m trying to
understand
C++ techniques for C practices.). I''d like to know a C++ programmer
accepted
way of removing the trailing ''\r'' from the result of one of the getline
formats. I don''t want to assume the ''\r'' is there so I''d appreciate some
options. I have heard that it''s supposed to be handled by the CRT of the
platform if I open the stream in text mode. Well I see only a binary mode
setting for the stream.



If you don''t open in binary mode then you are opening in text mode. IOW text
mode is the default. If you want to be sure then some simple string
manipulation can look for and remove a trailing ''\r''. I don''t think there is
any particular accepted method of doing this.

john


In article <sMd_c.65977


这篇关于输入输出流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆