Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

creating files named by user

Posted on 2000-04-11
3
Medium Priority
?
173 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
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
tvanceplus earned 400 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

876 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