C ++中CSV解析/编写的首选库是什么? [英] what's the preferred library for CSV parsing/writing in C++?

查看:447
本文介绍了C ++中CSV解析/编写的首选库是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到这个主题:如何在C ++中读取和解析CSV档案?

但似乎很重要的是,为了像CSV解析器这样通用的东西重新开发。 Boost有一些例程可以帮助解析,但没有一些开箱即用的东西。

but it seems silly to reinvent the wheel for something as universal as a CSV parser. Boost has some routines which facilitate parsing, but doesn't have something out of the box.

在其他地方,我看到推荐的库绑定到.NET或其他平台特定。很难相信没有一个首选的开放式C ++库为这个例程做一些事情。

Elsewhere, I see recommended libraries that are tied to .NET or otherwise platform specific. It's hard to believe that there isn't a preferred open C++ library to do something for this routine.

任何建议?

推荐答案

CSV解析,因为在C ++中编写自己的解析器比下载一些库更容易,读取如何使用它,将其链接到您的代码,可能遇到一些错误,更改代码以满足您的需求等。
CSV解析是微不足道的,有三件事你需要做:

There's no "preferred" library for CSV parsing because it is less effort to write your own parser in C++ than to download some library, read how to use it, link it with your code, potentially encounter some bugs, change code to suit your needs etc. CSV parsing is trivial, there are three things you need to do:


  • 检测字段分隔符。

  • 检测行分隔符。

  • 跳过在引号内的分隔符。

文件编码,您要使用的分隔符,文件中的额外空格和空行等。

Also there's an issue with file encoding, which delimiters you want to use, extra spaces and empty lines in file, and so on.

如果您仍然想使用首选CSV解析器,你应该完全跳过C ++中的编码并移动到其他语言。

If you still want to use "preferred" CSV parser then maybe you should completely skip coding in C++ and move to some other language.

这篇关于C ++中CSV解析/编写的首选库是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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