通过C ++在CSV中使用Unicode数据传输 [英] Unicode Data transfer Using in CSV by C++

查看:92
本文介绍了通过C ++在CSV中使用Unicode数据传输的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从数据库(如MS Sql)读取unicode数据,并尝试写入.CSV文件.我无法正确编写它,而已将其替换为"???".

有人有什么主意吗?

当我在MYSQL数据库中存储Unicode数据时,我遇到了同样的问题.但是我通过将wsrting转换为utf8来解决了这个问题.

I am reading a unicode data from a data base say MS Sql and trying to write in .CSV files. I am not able to write it properly it is replacing with ''???''.

do any one has any idea?

Same problem i was facing when i was storing a unicode data in MYSQL data base.but i fixed this issue by converting wsrting to utf8.

推荐答案

从存储中可以知道,这是一个转换问题.数据库文件通常使用UTF-8,而Windows使用UTF-16LE(wchar). CSV文件主要不是Unicode,而是纯文本.您应该检查应该用于读取CSV文件的程序是否支持Unicode编码的CSV文件以及哪种编码.如果没有,您可以转换为ANSI代码页.

一般而言:
从数据库读取:将UTF-8转换为wchar进行处理
写入数据库:将wchar转换为UTF-8
写入CSV:将wchar转换为接收程序支持的编码

编写UTF文件时,应将BOM标记放置在文件的开头.

Jochen Arndt
As you know from storing, it is a conversion problem. Database file usually use UTF-8 while Windows uses UTF-16LE (wchar). CSV files are mainly not Unicode but plain text. You should check if the program that should be used to read the CSV file supports Unicode encoded CSV files and which kind of encoding. If not, you may convert to an ANSI codepage.

In general:
Read from DB: Convert UTF-8 to wchar for processing
Write to DB: Convert wchar to UTF-8
Write CSV: Convert wchar to the encoding supported by the receiving program

When writing UTF files, you should place the BOM marker at the begin of file.

Jochen Arndt


这篇关于通过C ++在CSV中使用Unicode数据传输的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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