如何在 C++ 中将彩色内容打印到 CSV 文件中

how to print colored contents into csv file in c++

本文关键字:打印 文件 CSV 彩色 C++      更新时间:2023-10-16

我正在尝试将颜色值打印到输出文档或某些支持颜色的文件中,我发现将彩色值打印到控制台中,但它没有应用文件输出值,我尝试了几个头文件rang.hpprlutil.h,但两者都很有用,但仅用于在控制台中打印而不是用于输出文件。 这是我的尝试代码

#include<iostream>
#include<fstream>
using namespace std;
void PrintColoredFile(ofstream& outfile)
{
outfile<<"red,blue"<<endl; //I don't know how to print coloured values
outfile<<"This is a red colored message, This is a blue colored message"<<endl;
}
int main()
{
ofstream outFile.open("My_ColouredFile.doc",ios::out);
if(!outFile)
exit(1);
PrintColoredFile(outFile);
return 0;
}

这不是一个重复的问题,我到处尝试,但没有找到解决这个问题的方法请帮助我

CSV 代表逗号分隔的值。不能在 csv 文件中存储任何颜色值。它是纯文本。

通常Microsoft Excel是打开csv文件的标准工具。如果您将某些文本设置为彩色并想要保存该 csv 文件,Excel 会告诉您一些其他信息无法存储并且会丢失。