Hi folks, this is my first time here. Great site, I gained a great deal from the tutorials! I have looked everywhere for a solution to my problem, hopefully you guys will be able to help.

Basically my program prompts the user whether or not they would like to save the session as a text file.
Code:
do
{
cout<<"Create textfile (y/n) ?";
getline(cin,createdatafile);
}
while(createdatafile!="y" && createdatafile!="n");

if(createdatafile=="y")
  ofstream datafile ("datafile.txt");
Now if that if-statement is there, the program will give me an error:
error C2065: 'datafile': undeclared identifier

When that if statement is not there (aka will always create a txt file) it works perfectly (as in it creates the text file).

How do I make it so I can control whether or not it creates a text file?

Thanks,
Zahid