Solved

creating files named by user

Posted on 2000-04-11
3
168 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

740 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