Solved

creating files named by user

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

Technology Partners: 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

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…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

734 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