Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Save the content to a file

$
0
0
I am suppoed to save the information that the user inputs to a file that the user names.

#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?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>