GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / 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 12-Oct-2003, 15:19
mohammed mohammed is offline
New Member
 
Join Date: Oct 2003
Location: In Egypt
Posts: 2
mohammed is an unknown quantity at this point

How to open file in c++


hi,
fisrt, I would to thank you very much for your help. But I still want to know more about this class and how can I read data form file and write to it. And with this class I want to add item, delete item search for item. Please I need your help.
  #2  
Old 14-Oct-2003, 14:38
calculus87's Avatar
calculus87 calculus87 is offline
Junior Member
 
Join Date: Sep 2003
Location: FLorida
Posts: 41
calculus87 is on a distinguished road

hello


This might all be review for ya. If it is I appologize. Just trying to help.

Here is how you create a file.
fstream output;

output.open("file.txt", ios::out);
the ios::out allows you to take stuff from the file

output.open("C:\\storage\\file.txt", ios::out);
you need to use two \ when specifying the exact path, because when in quotes " " the backslash (\) is like a key word
for example cout<<"h\ti"; will put a tab between the h and the i.

output.open("file.txt", ios::in);
allows you to put stuff in the file

output.open("file.txt", ios::out||ios::in);
allows you to do both

string temp;
while(getline(output,temp))
cout<<temp;
The getline will get a line from output and store it in temp, because it is in the while loop it will go through the entire file.

ouput<<"the dog is in the house"<<endl;
this will allow you to put the string into the file.

output>>temp;
this will allow you to take 1 word from a file. (takes till it finds a space or tab, i beleive)

output.close();
this will close the file

remove("file.txt",);
this will delete the file from existance


Any other question, I will try to help
~Ronald
__________________
This message is a natural product made from recycled electrons. The slight
variations in spelling and grammar enhance its individual character and
beauty and in no way are to be considered flaws or defects.
  #3  
Old 02-May-2006, 10:56
BobbyMc BobbyMc is offline
New Member
 
Join Date: May 2006
Posts: 2
BobbyMc is on a distinguished road

Re: How to open file in c++


I am trying to do something similar. i need to do a find and replace in a .txt file. can anyone advise?

thanks
BMc
  #4  
Old 02-May-2006, 14:15
ubergeek ubergeek is offline
Regular Member
 
Join Date: Jan 2005
Posts: 775
ubergeek is a jewel in the roughubergeek is a jewel in the roughubergeek is a jewel in the rough

Re: How to open file in c++


once you read the file into a string, you can use the string.find(), .erase(), .insert(), and .replace functions
  #5  
Old 02-May-2006, 17:10
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,234
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: How to open file in c++


Quote:
Originally Posted by BobbyMc
I am trying to do something similar. i need to do a find and replace in a .txt file. can anyone advise?

thanks
BMc
Dang! Resurrecting a 3 year old thread... To ask a non-question.

Please review Guidelines #1, #2, #5, #7 (emphasis on "in progress") which I assumed you already read at least once...
__________________

Cow: You're a lawyer too?
Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase!
 

Recent GIDBlog2nd Week of IA Training 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
open files C++ calculus87 CPP / C++ Forum 4 09-Aug-2006 11:42
Limited file size.... lament Apache Web Server Forum 2 31-May-2004 13:35
How to search a huge text file for data? JdS MySQL / PHP Forum 7 27-May-2003 09:27
Sydog's DVD to Divx Conversion Guide asanthadenz Computer Software Forum - Windows 1 14-Mar-2003 14:08
How Do i get php to find out the file type of a file for me? viperman95833 MySQL / PHP Forum 2 08-Mar-2003 09:48

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

All times are GMT -6. The time now is 04:35.


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