IOStream库有什么严重的替代品? (除了cstdio) [英] What serious alternatives exist for the IOStream library? (besides cstdio)

查看:256
本文介绍了IOStream库有什么严重的替代品? (除了cstdio)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个类似于iostreams的库,它执行转换,并允许写入内存缓冲区,文件和控制台。但是,我想要类型安全,因为iostream是。是否有任何严重的图书馆这样做?

I'm looking for a library which operates similar to iostreams, in that it performs conversions, and allows writing to memory buffers, files, and the console. However, I'd like something type safe, as iostream is. Are there any serious libraries which do this?

能够指定输出编码的东西将是一个加号。

Being able to specify the output encoding for things would be a plus.

请注意,我不感兴趣的库,只是前面iostreams,因为他们只是添加更多复杂性iostreams正在做什么,例如 boost :: format

Note that I'm not interested in libraries which simply front iostreams because they just add more complexity to what iostreams is doing, e.g. boost::format.

PreEmptive注释响应:我不想使用cstdio,因为使用该系统不可能有代码输出位置不可知。也就是说,你必须调用一个函数将东西发送到缓冲区,你必须调用另一个函数将文件发送到控制台等。

PreEmptive comment response: I don't want to use cstdio because using that system it's impossible to have code be output location agnostic. That is, you have to call one function for sending things to buffers, and you have to call another function to send things to files, and another for the console, etc.

编辑2:回应下面的评论:我厌倦了iostreams和cstdio。这里有更具体的原因。我试图保持我的咆哮这个问题,但人们不断问我,如果我离开摇摆,所以这里是我的理由。

In response to the flurry of comments below: I'm fed up with both iostreams and cstdio. Here are more specific reasons. I tried to keep my "rant" out of this question, but people keep asking my if I'm off my rocker, so here's my rationale.


  • 无法正确处理Unicode字符

  • 无法写入字符串而无需手动缓冲管理

  • 通常需要支持非标准扩展(例如 vsnprintf )才能使用(编辑:好,C99的标准库

  • 无法在不更改原始代码的情况下更改输出的位置(非标准扩展,例如在glibc中,您可以将文件指针视为一个缓冲区,这是这样的...但它仍然只是一个非标准的扩展)

  • 使安全有趣(整个章节专门在安全文档解释问题,例如使用printf的格式字符串等)

  • 不类型安全

  • Can't handle Unicode characters correctly
  • Can't write into something like a string without doing manual buffer management
  • Often requires support of nonstandard extensions (e.g. vsnprintf) in order to be usable ( Okay, C99's standard library being in C++11 adds most/all of these now)
  • Can't change the location of output without changing the original code (nonstandard extensions e.g. in glibc allow you to treat a file pointer as a buffer, which kind of does this... but it's still just that, a nonstandard extension)
  • Makes security "fun" (to the point where entire chapters are dedicated in security docs explaining issues, e.g. with "printf"'s format strings and such)
  • Not type safe


  • 对客户来说过于复杂。如果你只使用标准库里的东西,这是伟大的,但试图扩展的东西是不可能的。我阅读了整个标准C ++ IOStreams和语言环境书 - 这本书看似主题 - 两次 - 我仍然不知道发生了什么。

  • Slow
  • Entirely too complicated to a client. If you use only what comes with the standard library it's great, but attempting to extend things is next to impossible. I read the entire "Standard C++ IOStreams and Locales" book -- the only book seemingly available on the topic -- twice -- and I still don't know what's going on.

我喜欢iostreams的概念,甚至使用运算符<< 不是,但它似乎完全过于设计给我。有人不应该花费无数小时阅读书籍,以便成为图书馆的简单客户。当然,如果你添加一个新的输出源或类似的东西,我可以理解,但....客户端应该被屏蔽这种复杂性。 (这不是库的用途?)

I love iostreams in concept, even the use of operator<< which some people seem to not like, but it seems entirely too over engineered to me. Someone should not have to spend countless hours reading books in order to be a simple client of your library. Sure, if you're adding a new output source or something like that I could understand, but.... clients should be shielded from that complexity. (Isn't that what a library's for?)

这是关于C ++中唯一在其他编程语言中只是工作的痛苦,我看不到原因很复杂。

This is about the only thing that's painful in C++ that "just works" in other programming languages, that I see no reason to be complicated.

推荐答案

提高精神。 a href =http://www.boost.org/doc/libs/release/libs/spirit/doc/html/spirit/qi/tutorials/quick_start.html =nofollow> Qi for输入, Boost Spirit Karma 输出。可以读/写任何可以表示为迭代器范围的内容。

Boost.Spirit.Qi for input, Boost.Spirit.Karma for output. Can read from/write to anything that can be represented as an iterator range.

这篇关于IOStream库有什么严重的替代品? (除了cstdio)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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