Solved

creating files named by user

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 learn how to clear a vector as well as how to detect empty vectors in C++.

746 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now