如何将percision格式复制到文本文件

How do I copy percision formatting to text file?

本文关键字:文本 文件 复制 格式 percision      更新时间:2023-10-16

我无法弄清楚如何在控制台窗口中复制我的文本格式,我也将其复制到文本文件以将其复制到成绩。

我正在使用的文本文件命名为csis。

我尝试用COUT代替CSIS以相同的行,通常可以使用。

但是,这给出了一个错误:名称空间std没有成员CSI,这很有意义。那么,如何将相同的主机复制到文本文件CSIS?

//example of function with the problem
//print percentage of pairs dealt
void Game1::printPairsPercentage() {
    pairHands = pairs / hands;
    std::cout << std::fixed;
    std::csis << std::fixed;
    std::cout << std::setprecision(2);
    std::csis << std::setprecision(2);
    std::cout << setw(15) << pairHands << "%" << endl;
    std::csis << setw(15)<< pairHands << "%" << endl;

//错误:名称空间std没有成员CSIS

尝试在诸如此类的文件上创建文件,然后输出到文件中:

#include <fstream>
//example of function with the problem
//print percentage of pairs dealt
void Game1::printPairsPercentage() {
    std::ofstream csis("Path to text file");
    pairHands = pairs / hands;
    csis << std::fixed;
    csis << std::fixed;
    csis << std::setprecision(2);
    csis << std::setprecision(2);
    csis << setw(15) << pairHands << "%" << endl;
    csis << setw(15)<< pairHands << "%" << endl;
}