Add a program that allows the user to enter any number of integers to be written to the file. You may use the cin.eof () function or a specific value to end the user input. After the file is written, close it, reopen it as input and read and display the data in it. All file handling processes should be in their own function.
right now my code is like this but line 15 is undeclare. anyone know how to fix it ? sorry for my bad English.
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib> // Needed for exit()
using namespace std;
int main()
{
ifstream inputFile;
string fileName;
int value, x;
cout << "Enter the file name: ";
getline(cin, fileName);
inputFile.open(fileName.c_str());
outputFile.open(fileName.c_str());
if(inputFile.fail())
{
cerr << "Error Opening File" << endl;
return(1);
}
int number;
do
{
inputFile >> number;
if (!inputFile.eof())
cout << "number" << " " << endl;
} while (!inputFile.eof());
inputFile.close();
do
{
cout << "Pick a number between 1 through 100. ";
int value;
cin >> value;
} while (value < 1 || value > 100);
string word;
int number;
int count = 0;
infile >> number;
while (!inputFile.eof())
{
if (number == x)
{
sum1++
}
inputFile >> number;
}
cout << sum1;
while (!inputFile.eof())
{
inputFile >> word;
if (word == "input")
{
count++;
}
}
outputfile.close();
inputFile.close();
return 0;
}