Problem with files

Hi people, i was trying this program while understanding the basics of input/output a txt file.
SO this is a program while asks the user to input the name of the text file.
If it exists, then it will read it else, it will create it and it will prompt the user for some input. Thereafter, it will read the same file again...
here is the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<fstream.h>
#include<iostream.h>
#include<string.h>
#include<conio.h>
using namespace std;
int main()
{
    char a[34];
    string line;
    do{
    cin.getline(a, 34);
    ifstream tanmay;
    tanmay.open(a);
    if(tanmay.is_open())
    {
                        while(!tanmay.eof())
                        {
                                            getline(tanmay, line);
                                            cout<<line<<endl;
                                            }
                        }
                        
                        else 
                        {
                             ofstream tammy;
                             tammy.open(a);
                             cout<<"input something\n";
                             string line2;
                             cin>>line2;
                             tammy<<line2;
                             tammy.close();
                         }
                         }
                         while(!tanmay.is_open());
 getch();
 return 0;   
}

But after compiling, i am getting an error of keeping- tanmay as undeclared..
But, if i am right, i have already declared tanmay.
So can you tell me where i am wrong?
THANKS A LOT ...
Topic archived. No new replies allowed.