creation of data file

i want to create a simple text file in c++ but i want to take the name of the file from the user.i have come up with the source code below but no creation of text file is taking.
please help me.....and it's urgent as their is a deadline for me.
in the source code below the user has to enter the file's name which is to be created and the user has to enter the text that is to be stored in the file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
void main()
{
clrscr();
fstream fout;
char x[50];
cout<<"please enter the file name which is to be created:";
cin>>x;
fout.open("x",ios::out);
char str[500];char ch;
do
{
cout<<"enter the text here"<<endl;
cin>>str;
cout<<"do you want to enter more?"<<endl;
cin>>ch;
}while(ch=='Y'|| ch=='y');
fout.close();
}


p.s. there are no errors and i program on turbo c++
Last edited on
> there are no errors and i program on turbo c++
hilarious.
The headers are `iostream' and `fstream' without the .h
There are namespaces. `cout' `cin' `fstream' are in the std namespace.
main must return int.
¿is it right and just to use conio.h?

You may want to fix your indentation too.


> i have come up with the source code below but no creation of text file is taking.
The file `x' is created. It's empty as you didn't write on it.
@ne555

Thanku for atleast replying.
I corrected my code without anyone's help.....so it's okay.....!
and might i inquire what is so hilarious about writing...."there are no errors and i program on turbo c++"?
I just wanted to share whatever info i hv.
Topic archived. No new replies allowed.