숫자가있는 cvs 파일을 인쇄해야합니다. 파일을 인쇄 할 때 점이있는 숫자가 있지만 쉼표로 숫자가 필요합니다.C++ 점으로 표시되는 대신 쉼표로 두 자리 숫자로 파일을 인쇄하는 방법
여기 예입니다. 로케일 방법을 사용하여 터미널에서이 번호를 인쇄 할 경우 쉼표로 숫자를 얻지 만 파일에는 같은 번호이지만 점이 있습니다. 나는 왜 그런지 이해하지 못한다. 어떻게하면됩니까?
#include <iostream>
#include <locale>
#include <string> // std::string, std::to_string
#include <fstream>
using namespace std;
int main()
{
double x = 2.87;
std::setlocale(LC_NUMERIC, "de_DE");
std::cout.imbue(std::locale(""));
std::cout << x << std::endl;
ofstream outputfile ("out.csv");
if (outputfile.is_open())
{
outputfile <<to_string(x)<<"\n\n";
}
return 0;
}
미리 감사드립니다.
imout the of object, of cout이 아닙니다. –
@Neil [도움이되지 않는 것 같습니다] (http://coliru.stacked-crooked.com/a/2947e8488c8fb6a2). –
'std :: setlocale'에''을 포함해야합니다. 헤더 없이도 작동하지만 보증은 없습니다 (예를 들어 Visual C++에서는 컴파일없이 컴파일되지 않습니다). –