入力ファイルから情報を読み取り、そのデータを出力ファイルに書き込む方法を理解しようとしています。ファイルから読み取り、その内容を表示する方法は理解していますが、ファイルに書き込む方法や内容を表示する方法は理解していません。私のプログラムは正常に動作しますが、出力 txt ファイルを確認すると、何もありません! 私は何が間違っているのでしょうか?入力ファイルには 3.1415 2.718 1.414 が含まれています。
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
float fValue;
fstream inputFile;
ofstream outputFile;
inputFile.open("C:\\Users\\David\\Desktop\\inputFile.txt");
outputFile.open("C:\\Users\\David\\Desktop\\outputfile.txt");
cout << fixed << showpoint;
cout << setprecision(3);
cout << "Items in input-file:\t " << "Items in out-put File: " << endl;
inputFile >> fValue; // gets the fiest value from the input
while (inputFile) // single loop that reads(from inputfile) and writes(to outputfile) each number at a time.
{
cout << fValue << endl; // simply prints the numbers for checking.
outputFile << fValue << ", "; // writes to the output as it reads numbers from the input.
inputFile >> fValue; // checks next input value in the file
}
outputFile.close();
inputFile.close();
int pause;
cin >> pause;
return 0;
}