hello there, im new to this site and ive been looking for ages to try and find a way of doing it, what i need to do is create a text file that the user will name and it will then write the data to it, ive tried numerous ways and the best ive come up with is writing to the file but i cannot get it so the user enters the file name
any help will be greatly appreciated, cheers!
#include<iostream>
#include <Windows.h>
#include <stdio.h>
usingnamespace std;
char decision;
int main()
//insert code to allow user to enter file name
do
{
//user inserts number of points they wish to be plotted
cout<<"\n Please enter the number for the amount of sample points ";
cout<<"\n (the number has to be odd and has to be between 3 and 31) : \n\n" ;
cout<<"\n Output waveform for (number) sample points: ";
cout<<"\n
//ask user if they would like to re run the program
cout<<"\n Would you like to re-run the program? y/n :\n";
cin>> decision;
}
while (decision == 'y' || decision == 'Y');
if (decision == 'n' || decision == 'N')
{
//end program and message
system ("Pause");
return 0;
}
#include<iostream>
#include <Windows.h>
#include <stdio.h>
#include <fstream>
usingnamespace std;
char decision;
int main()
{
//insert code to allow user to enter file name
ofstream programdata;
outputFile.open("programdata.txt");
do
{
//user inserts number of points they wish to be plotted
cout<<"\n Please enter the number for the amount of sample points ";
cout<<"\n (the number has to be odd and has to be between 3 and 31) : \n\n" ;
cout<<"\n Output waveform for (number) sample points: ";
//ask user if they would like to re run the program
cout<<"\n Would you like to re-run the program? y/n :\n";
cin>> decision;
}
while (decision == 'y' || decision == 'Y');
if (decision == 'n' || decision == 'N')
{
//end program and message
}
outputFile.close();
system ("Pause");
return 0;
}
and it worked the first time i did it but now it says
Error: identifier "outputFile" is undefined
and i also need to be able to change the name of the file i tried setting it so that the name of the variable would be from a string but i couldn't get that to work either
im getting really stuck with it as i get so far and then i could enter the name of the file but then it didnt actually create a file and then when i ran the program again it bypassed all user inputs and closed the program
thankyou for the quick reply :)
woops my mistake aha sorry about that, so how can i go about changing the name of the file then? am i going in the right direction by using a string that takes the user input + .txt and outputting that to programdata.open ?