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:
#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 ...