Solved

creating files named by user

Posted on 2000-04-11
3
171 Views
Last Modified: 2010-04-02
I'm working with a project for my data structures class and i need to create blank files to send information to and they need to be given a name entered by the user of the program.

Example:
   The user is going to enter information on a town named Charleston.  How do i create a file with the name Charleston once the user enters the name of the town.

I already made the class that sends the data to an external file but only if the name of the output file is given by me in the code.
0
Comment
Question by:datavirus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
tvanceplus earned 100 total points
ID: 2705645
#include <fstream.h>

you have a char* filename that contains
the filename that the user entered.

ofstream out;
out.open(filename); //create and open
                    //file for writing
out.close(); //close the file

Good Luck!
0
 

Author Comment

by:datavirus
ID: 2705785
but how do I write to that file I create?
0
 
LVL 1

Expert Comment

by:tvanceplus
ID: 2708142
you use standard insertion operators like this


int data=564;

out.open(filename);

out<<data;

out.close();

a text file with the name stored in filename will be create which will look like this

564

the insertion operator is used the same way as it is for cout
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question