Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 15th, 2006, 7:13 PM   #1
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
saving to a file

Can someone please tell me how to save to a file ?? I'm trying to save a string type into a file at "C:\testing.text" i have a while loop and everytime the loop goes through i need to save to the next line in a file. Any help would greatly be appreciated.
Eric the Red is offline   Reply With Quote
Old Feb 15th, 2006, 8:03 PM   #2
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
sorry for the double post ignore the other one
Eric the Red is offline   Reply With Quote
Old Feb 15th, 2006, 8:22 PM   #3
Animatronic
Programmer
 
Join Date: Jun 2005
Posts: 99
Rep Power: 4 Animatronic is on a distinguished road
Your looking for the fstream family of classes in the standard library. This page looks to be a good start.
Animatronic is offline   Reply With Quote
Old Feb 16th, 2006, 7:12 AM   #4
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
something like this...

// Appends to existing file.
void WriteToFile (string line)
{
	string strFile = "c:\testing.text";
	fstream theFile;
	theFile.open(strFile.c_str(),std::ios::app);
	theFile << line << endl;
	theFile.close();
}
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Feb 16th, 2006, 7:31 AM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
If you're operating on Windows (neither your post nor your personal info say), I recommend you use binary mode, rather than the default text (*nix is always binary). The reasons are made clear in MS's documentation of the modes.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Feb 16th, 2006, 8:05 AM   #6
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
thx

prefect this is great guys.. i just thought that it would be harder than this.
Eric the Red is offline   Reply With Quote
Old Feb 16th, 2006, 8:30 AM   #7
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
I always seemed to do things the hard way first, for some reason... I still do.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Feb 16th, 2006, 10:27 AM   #8
babbling
Newbie
 
Join Date: Feb 2006
Posts: 11
Rep Power: 0 babbling is on a distinguished road
But don't forget to do error checking!
babbling is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:00 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC