![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
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.
![]() |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
sorry for the double post ignore the other one
|
|
|
|
|
|
#3 |
|
Programmer
Join Date: Jun 2005
Posts: 99
Rep Power: 4
![]() |
Your looking for the fstream family of classes in the standard library. This page looks to be a good start.
|
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() ![]() |
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." |
|
|
|
|
|
#5 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#6 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
thx
prefect this is great guys.. i just thought that it would be harder than this.
|
|
|
|
|
|
#7 |
|
Programming Guru
![]() ![]() ![]() |
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." |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Feb 2006
Posts: 11
Rep Power: 0
![]() |
But don't forget to do error checking!
__________________
Canonical Books: The best programming books around. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|