GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 20-Apr-2004, 08:05
Nelly Nelly is offline
New Member
 
Join Date: Apr 2004
Posts: 15
Nelly is on a distinguished road

creating new file


Hello,

I have a file for (example File1.vid), which I'm extracting some feature from it and saving those feature in a vector.

I need to save that vector in a new file, giving it the same name as "File1", but with a differrent extension, for eg, ".txt".

How do I go about creating that new file.

Can anyone help
  #2  
Old 20-Apr-2004, 11:46
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Well, you can use stream I/O to do it.

CPP / C++ / C Code:
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
  int data;
  ofstream outFile; // Declares an output stream called outFile
  
  outFile.open("C:\\somefolder\\somedata.txt");
  // opens somedata.txt for writing -- will be created if it doesn't exist

  cin >> data;
  outFile << data; // Sends the value of "data" to outFile

  outFile.close();

  outFile.open("C:\\somefolder\\someMoreData.txt",ios::app);
  // opens someMoreData.txt for writing and appending
  // it will be created if it doesn't exist. data in the file will not be
  // overwritten.

  outFile << data;
  outFile.close;

  return 0;
}
__________________
-Aaron
  #3  
Old 21-Apr-2004, 02:56
Nelly Nelly is offline
New Member
 
Join Date: Apr 2004
Posts: 15
Nelly is on a distinguished road
Thank you,

But say:

my original file was ("C:\\somefolder\\somedata.vid"),

After reading my data from the original file,

I need my outputfile to be:
outFile.open("C:\\somefolder\\somedata.txt");

That means only the 'ext' changes but the name stays the same.

How do I do that?
  #4  
Old 21-Apr-2004, 05:12
vadharah vadharah is offline
Junior Member
 
Join Date: Apr 2004
Posts: 45
vadharah is on a distinguished road
Quote:
Originally Posted by Nelly
Thank you,

But say:

my original file was ("C:\\somefolder\\somedata.vid"),

After reading my data from the original file,

I need my outputfile to be:
outFile.open("C:\\somefolder\\somedata.txt");

That means only the 'ext' changes but the name stays the same.

How do I do that?

ok if u look at the other threads sent earlier on there is one sent by vadharah
entitled "about file names " read the replies he got. one of them answers ur question.
  #5  
Old 21-Apr-2004, 06:14
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
How do I change the extension of a file?
  #6  
Old 22-Apr-2004, 02:35
Nelly Nelly is offline
New Member
 
Join Date: Apr 2004
Posts: 15
Nelly is on a distinguished road
Thank you very much for your help
 
 

Recent GIDBlogMeeting the populace by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CD burner wont burn!! robertli55 Computer Hardware Forum 1 18-Jun-2004 10:53
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 11:28
Re: Programming Techniques WaltP C Programming Language 0 09-Mar-2004 23:56
C++ file I/O CronoX C++ Forum 36 09-Mar-2004 17:28
read specified range of lines from file etron C Programming Language 8 18-Feb-2004 08:04

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:46.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.