使用文本文件中的值进行计算并写入另一个文本文件
Calculation with values from a text file and write into another text file
我想从文本文件中获取一些值,并在 c++ 中将这些值与固定数字相乘。然后我想将每个值的解决方案写入另一个文本文件中。这是我的代码:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
std::ifstream infile("Test_60.txt");
std::ofstream outfile("Output.txt");
int main(int argc, char** argv)
{
double max, min, d, s, m;
max = 0;
min = 1;
double x, y, z, R, G, B;
while (infile >> x >> y >> z >> R >> G >> B)
{
if (max < x)
{
max = x;
}
if (min > x)
{
min = x;
}
d = max - min;
s = 60 / d;
m = s*x;
}
outfile << m << endl;
infile.close();
outfile.close();
system("pause");
return 0;
}
最小值和最大值已经起作用,但是当我尝试将其写入文本文件时,我只得到一个x
(或m
)值。最后,我想要一个文本文件,其中包含 x 和 y 的乘法值以及输入文件中的 z、R、G、B 值。
此致敬意。
你必须
把语句
max = 0;
min = 1;
进入 while 循环,以确保最小/最大复位。
相关文章:
- 文本文件中的单词链表
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 如何将内容数组写入文本文件?
- 无法通过空白将文本文件行分隔为矢量
- 我正在使用嵌套的while循环来解析具有多行的文本文件,但由于某种原因,它只通过第一行,我不知道为什么
- C++将文本文件中的数据读取到结构数组中
- 在指针的帮助下,文本文件中单词的频率
- 将字符指针十六进制转换为字符串并保存在文本文件C++中
- 将值从二维数组输出到文本文件
- 如何在c++中从文本文件中逐行读取整数
- 从文本文件中读取时钟时间和事件时间并进行处理
- 如何从文本文件中读取值和数组
- 如何在C++中确定文本文件中的元素是字符还是数字
- C++试图读取一个文件并输出到另一个文本文件
- 如何通过套接字将文本文件的内容从服务器发送到客户端
- 已修改的LinkedList未在文本文件本身中更新
- C++文本文件的获取线
- 为什么C++的文件 I/O 在读取文本文件时忽略初始空行?我怎样才能让它不这样做?
- 打印逐行存储的文本文件
- C++文本文件输入