473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

c++ getting the filename and path of an ofstream object

I'm passing an ofstream object to a function within my program. In that function, I'd like to extract the path and filename of the ofstream object, modify the filename only, create a new ofstream object using the old path and new filename and write something to it.

How do I get the path and filename of a passed ofstream object?

Expand|Select|Wrap|Line Numbers
  1. std::ostream& Func::writeOut(std::ostream& out)
  2. {
  3.    std::string sPath = getPath(out)     // how do I implement this?
  4.    std::string sFile = sPath + "//NewFile";
  5.  
  6.    std::ofstream oFile(sFile, std::ios::out);
  7.  
  8.    sFile << "Write something" << std::endl;
  9.  
  10.    return(out);
  11. }
  12.  
Apr 23 '10 #1
1 6019
newb16
687 512MB
You can't because ostream may be e.g. ostringstream that has no file associated with it.
Apr 23 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: Sean Ross | last post by:
Hi. Recently I made a small script to do some file transferring (among other things). I wanted to monitor the progress of the file transfer, so I needed to know the size of the files I was...
1
by: red floyd | last post by:
Is there any way to retrieve the filename given to a std::ofstream (passed in constructor or in ofstream::open())? Or, should I derive from ofstream (should probably be a template to handle...
5
by: cpp | last post by:
When I create an instance of ofstream, what is the name of the member variable that holds the filename? For example: ofstream ofs("Output.txt"); cout << ofs.WhatIsThePathVariable; If there...
2
by: Rob Cowie | last post by:
Hi, Given a string representing the path to a file, what is the best way to get at the filename? Does the OS module provide a function to parse the path? or is it acceptable to split the string...
4
by: Larry Tate | last post by:
I am wanting to get those cool html error pages that ms produces when I hit an error in asp.net. For instance, when I get a compilation error I get an html error page that shows me the ...
0
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) :...
0
by: smanisankar | last post by:
hi, the following is the full page code for uploading a file to server. since i got no idea to overwrite the file, i want delete the file if the file is already uploaded. i got the folder name...
7
by: Hitesh | last post by:
Hi, I have a small script here that goes to inside dir and sorts the file by create date. I can return the create date but I don't know how to find the name of that file... I need file that is...
8
by: sheriff | last post by:
Hi friends, I am opening and reading a file and writing it in a new file. int main() { ifstream inputFile("C:\\TEMP\\test.txt"); ofstream outputFile; ...
1
by: Moot | last post by:
The scenario is that I am processing a large text file and moving each line to one of a number of other files based on some criteria. I have an array of file pointers with writable files. I have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.