Comments

Monday, October 8, 2012

Filling And Data Write in File by User

Posted by at 2:34 PM Read our previous post


Write a program which can create files and saved messages into then fulfilling the following requirements.
Program should be able to:
a. create a file with the name specified by the user.
b Save the file at a path defined by the user.
c Save the message in the file given by the user.


Source code

#include <iostream>
#include <fstream>
using namespace std;
void main()
{
       char input[50],username[20];
       ofstream myfile;
       cout<<"Enter your file name and format"<<endl;
       cin.getline(username,20);
       myfile.open(username,ios::app);
       cout<<"Type your message here"<<endl;
       cin.getline(input,20);
       myfile<<"The message is "<<input<<endl;
       myfile.close();
}
Output
 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Popular Posts

Labels

© Codepirate is powered by Blogger - Template designed by Stramaxon - Best SEO Template