I have the piece of code:
outfile.open (filename.c_str());
where filename is the filename provided by the user.
However, how would I add .csv to end of that so I can change the file extension and create a new file?
so basically the outfile name would look like this
filename.txt.csv
-jeff
7 1514
You want to create an entirely new file (ie, copy the original into a new location and leave the first untouched)?
There are two ways to do this. The first is the ugly, QAD way to use 'system()' and the OS-dependent commands to do that (Linux would be 'cp /file/path/1 /file/path2', I'm not sure what it would be in DOS).
The second is the more elegant way to use the API of the OS you are on (I'm guessing this is Windows, you'd have to use the Win32 API).
Or did I completely mis-understand your question?
You want to create an entirely new file (ie, copy the original into a new location and leave the first untouched)?
There are two ways to do this. The first is the ugly, QAD way to use 'system()' and the OS-dependent commands to do that (Linux would be 'cp /file/path/1 /file/path2', I'm not sure what it would be in DOS).
The second is the more elegant way to use the API of the OS you are on (I'm guessing this is Windows, you'd have to use the Win32 API).
Or did I completely mis-understand your question?
user inputs the file name : filename.txt so the program can open and grab data off it.
then I want the program to grab the filename.txt (or whatever they type in) and add .csv to the end of it so it creates a new file, just in a different format..
Okay, so you just re-stated your question, but didn't answer mine. What happens to the original file? Does it still exist? Or are you actually changing the file?
The difference (in Unix) is :
cp /path/to/file1 /path/to/new/file
and
mv /path/to/file1 /new/path/to/thefile
In the first, you will be able to find file1 in both /path/to and /path/to/new. In the second /path/to/file1 no longer exists - it is now /new/path/to/thefile .
Do you see what I'm saying?
You also didn't post your OS.
Okay, so you just re-stated your question, but didn't answer mine. What happens to the original file? Does it still exist? Or are you actually changing the file?
The difference (in Unix) is :
cp /path/to/file1 /path/to/new/file
and
mv /path/to/file1 /new/path/to/thefile
In the first, you will be able to find file1 in both /path/to and /path/to/new. In the second /path/to/file1 no longer exists - it is now /new/path/to/thefile .
Do you see what I'm saying?
You also didn't post your OS.
Im using windows, but I think we are making this too difficult than it is.
cout << "Name of file" ;
cin >> filename ;
infile.open(filename.c_str());
outfile.open (filename.c_str())
not basically i want to add the extension .csv to the outfile so it won't be copying over the original file, but it will output all new info into the new file created.
so basically..
Name of file: data.txt (data.txt inputted by the user)
then all new info will be put into a new file called data.txt.csv
make sense?
You can just append ".csv" to the filename string, you know.
You can just append ".csv" to the filename string, you know.
what do you mean...i just trying to make a new file with a .csv extension...i don't mean to make this complicated..
what do you mean...i just trying to make a new file with a .csv extension...i don't mean to make this complicated..
Okay, so in your example, you open the original .txt file to copy, and then create the new .csv file to copy that into, so as Laharl said, it'd be something like -
string s_appendCsv = ".csv";
-
filename = filename + s_appendCsv;
-
fout.open(filename,'w');
-
(assuming filename is a string) That doesn't look exactly right to me, and I can't say 100% why, but I'll update this if I figure it out...
Sign in to post your reply or Sign up for a free account.
Similar topics
by: David Buchan |
last post by:
Hi guys,
This may be a dumb question; I'm just getting into C language here.
I wrote a program to unpack a binary file and write out the contents to
a new file as a list of unsigned integers....
|
by: Lokkju |
last post by:
I am pretty much lost here - I am trying to create a managed c++
wrapper for this dll, so that I can use it from c#/vb.net, however, it
does not conform to any standard style of coding I have seen....
|
by: Brian Henry |
last post by:
first question... I have a flat file which unfortinuatly has columns
seperated by nulls instead of spaces (a higher up company created it this
way for us) is there anyway to do a readline with this...
|
by: sani8888 |
last post by:
Hi
everybody I am a beginner with C++ programming. And I need some help.
How can I start with this program
***********
The program is using a text file of information as
the source of the...
|
by: Michael |
last post by:
Since the include function is called from within a PHP script, why
does the included file have to identify itself as a PHP again by
enclosing its code in <?php... <?>
One would assume that the...
|
by: Arquitecto |
last post by:
Hi ,
I have a question about a file operation i want to do . I have a data
file lets say X bytes . I want to read the file and delete a byte
every 2nd byte . I am a little comfused ,my approach...
|
by: allpervasive |
last post by:
hi all, this is reddy, a beginner to c lang,,here i have some problems
in reading and modifying the contents of a file,, hope you can help to
solve this problem. Here i attach the file to be...
|
by: =?Utf-8?B?R2lkaQ==?= |
last post by:
Hi,
In my windows applicationm, i need to excute a batch file.
this batch file throws some text and questions to the screen, i need to
catch the standard Output, check if it's a question, in...
|
by: amit.uttam |
last post by:
Hey everyone,
I've recently jumped big time into python and I'm working on a
software program for testing automation. I had a question about proper
logging of output. What I would like is:
1....
|
by: Reggie |
last post by:
Hi and TIA! I have a class file located in my root directory with all me
web pages. I call/use the class and it works fine. I have no imports
statements aspx or codebehind. My question is why? ...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |