我是C++的新手,我想知道如何输出/写入声明为double的变量到txt文件.我知道如何使用fstream输出字符串,但我无法弄清楚如何发送任何其他内容.我开始认为你不能发送任何东西,但字符串到文本文件是正确的吗?如果是这样,那么如何将存储在变量中的信息转换为字符串变量?
这是我的代码,我正在尝试实现这个概念,它相当简单:
int main()
{
double invoiceAmt = 3800.00;
double apr = 18.5; //percentage
//compute cash discount
double discountRate = 3.0; //percentage
double discountAmt;
discountAmt = invoiceAmt * discountRate/100;
//compute amount due in 10 days
double amtDueIn10;
amtDueIn10 = invoiceAmt - discountAmt;
//Compute Interest on the loan of amount (with discount)for 20 days
double LoanInt;
LoanInt = amtDueIn10 * (apr /360/100) * 20;
//Compute amount due in 20 days at 18.5%.
double amtDueIn20;
amtDueIn20 = invoiceAmt * (1 + (apr …Run Code Online (Sandbox Code Playgroud)