I am suppoed to save the information that the user inputs to a file that the user names.
Why can't I enter a file name and save the information to a file?
#include <fstream>
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main ( )
{
ofstream f;
string filename;
int numbers;
int seed;
int randNum;
cout<<"Enter a seed.\n";
cin>> seed;
cout<<"\nHow many numbers to generate?\n";
cin>> numbers;
for (int i = 0; i < numbers; i++)
{
cout << "["<< ((rand()) % 20 + 1) * 5 << "] " << endl;
}
cout << "Please enter a file name to write: ";
getline( cin, filename );
f.open( filename.c_str() );
f << seed;
f << numbers;
f.close();
cout << "Good job! Your file has been saved.\n";
}
Why can't I enter a file name and save the information to a file?