问题描述
我需要将CSV文件中的浮点数导出为英语本地设置中的十进制符号为,(逗号)".我确实将该数字用双引号引起来,以防止在导出到CSV之前对我的数字进行格式化,例如使用定界符选项卡将其导出为CSV例如"1,23456789".但是,当我查看该文件时,它显示为"123,456,789".即使我使用双引号,我的格式似乎也已更改.
请给我一些建议.
我正在使用cstring格式化浮点数到字符串.在excel和记事本中,这两个地方都显示了错误的值.以下是我的代码,
Hi,
I need to export floating numbers in CSV file with decimal symbol as ",(comma)" in english local settings. I did put that numbers in double quotes in order to prevent my numbers from being formatted before exporting to CSV for example "1,23456789" with the delimiter tab . But when I viewed the file it shows "123,456,789" . Seems like my format has been changed even though i have put in double quotes.
Please give me some suggestion.
I am using cstring to format the float to string. Both in excel and notepad, in both the places it is showing wrong value. Below is my code,
CFileStream _fileLog;
CString strDelimiter = _T("\t");
CString strQuote = _T("\"");
CString strContent;
strContent = strQuote + _T("1,23456789") + strQuote + strDelimiter +
strQuote + _T("9,12345678") + strQuote;
fileLog.Write(strContent);
推荐答案
#include <iostream>
#include <fstream>
using namespace std;
int main () {
fstream filestr;
string delim = "\t", quotes = "\"", content;
filestr.open ("test.txt", fstream::in | fstream::out | fstream::app);
content = quotes + "1,23456789" + quotes + delim;
content += quotes + "9,12345678" + quotes + delim;
filestr << content;
filestr.close();
return 0;
}
输出
Output
"1,23456789" "9,12345678"
这篇关于将浮点数导出到CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!