Your browser does not seem to support CSS. If images appear below, please disregard them.
It appears that you're running an Ad-Blocker. This site is monetized by Advertising and by User Donations; we ask that if you find this site helpful that you whitelist us in your Ad-Blocker, or make a Donation to help aid in operating costs.
Previous Thread
Next Thread
Print Thread
Rate This Thread
#17439 - 03/02/04 10:08 PM Files...creating if one doesn't exist.  
Joined: Dec 2003
Posts: 38
acid45 Offline
Junior Member
acid45  Offline
Junior Member

Joined: Dec 2003
Posts: 38
canada
Hey guys. What I'm trying to do is to a file based on the username. ie:
fstream saveout(filename);
where filename is the username + .txt0
0 being the end marker of a character array.

It's a character array so adding .txt isn't hard and if the file already exists it will write to that file;

I can't seem to find a way to create a file of filename name if(!saveout); I've checked a couple sites and found that this "can't" be done...ha!

It's prety sad when you start using; instead of . :p I just caught myself on the last sentence. Any ideas would be great. Sorry for the technical indifficulty.

Sponsored Links
#17440 - 03/02/04 11:26 PM Re: Files...creating if one doesn't exist.  
Joined: Dec 2003
Posts: 38
acid45 Offline
Junior Member
acid45  Offline
Junior Member

Joined: Dec 2003
Posts: 38
canada
-_-*
Code:
nfbuf = saveout.rdbuf();
nfbuf->open(filename, fstream::out);
saveout<< name << endl;

#17441 - 03/03/04 12:22 AM Re: Files...creating if one doesn't exist.  
Joined: Dec 2003
Posts: 38
acid45 Offline
Junior Member
acid45  Offline
Junior Member

Joined: Dec 2003
Posts: 38
canada
I can output a character array using this method but there are also integer properties to the class I'm trying to write to file. I'm trying to use filebuf *nfbuf; to output a name and a bunch of stats and save values to file which are integer and can't think of a way to convert an int into a *char other than String... any ideas would be greatly appreciated.

#17442 - 03/03/04 11:08 PM Re: Files...creating if one doesn't exist.  
Joined: Mar 2002
Posts: 1,273
SilentRage Offline
DollarDNS Owner
SilentRage  Offline
DollarDNS Owner

Joined: Mar 2002
Posts: 1,273
OH, USA
Somebody pointed me to this thread expecting me to answer it. But you're asking a C++ question, and I only deal with C. Will you be satisfied with the C solution? Basically all you want to do is create a file if it doesn't already exist? Also tell me if you will be using this on windows or linux or both?

As for converting ints to strings you can do this:

int intv = 123;
char strv[4];

itoa(intv, strv, 10);

OR

sprintf(strv, "%u", intv);


Domain Registration, Hosting, Management
http://www.dollardns.net
#17443 - 03/04/04 09:02 PM Re: Files...creating if one doesn't exist.  
Joined: Dec 2003
Posts: 38
acid45 Offline
Junior Member
acid45  Offline
Junior Member

Joined: Dec 2003
Posts: 38
canada
We're using windows as a common operating system between team members.

Well, I'm failry new to c/c++ and still haven't goten the grasp of how to use c and c++ inter-changably. I found how to use filebuf to create a file if it doesn't exist but this method doesn't make it easy to write to file with any format other than char*, which is why I wanted to know how to convert an int into a character array. I think if I can use itoa() then I will be well on my way to working in the map from the C version.

We had to chagne almost everything anyway because the system we had was usable for one map only and it would have taken a lot of coding to add new maps. The locig and math can be copied and pasted so we shouldn't have any problems converting most of the program. We just wanted to get the c - c++ differances out of the way.

Thanks for the input Rage.

Sponsored Links
#17444 - 03/04/04 10:22 PM Re: Files...creating if one doesn't exist.  
Joined: Mar 2002
Posts: 1,273
SilentRage Offline
DollarDNS Owner
SilentRage  Offline
DollarDNS Owner

Joined: Mar 2002
Posts: 1,273
OH, USA
so I take it you're not interested in the C solution?


Domain Registration, Hosting, Management
http://www.dollardns.net
#17445 - 03/13/04 05:21 AM Re: Files...creating if one doesn't exist.  
Joined: Dec 2003
Posts: 38
acid45 Offline
Junior Member
acid45  Offline
Junior Member

Joined: Dec 2003
Posts: 38
canada
I have the C solution thanks anyway, we're still trying to work it out theough we had it working with strings as I said, we should be able to get it done before the end of this week. It's a side porject me and another programmer have and are working on in between jobs and classes and shit. Going out into the workforce next week . Building a database for reporting and marketing info. Building a distributed system to make a user able to purchase access codes to the internet and then use the cod or x ammount of minutes and then have to purchase a new code. We also have to spiff up the website.


Member Spotlight
Gremelin
Gremelin
Portland, OR; USA
Posts: 7,195
Joined: February 2002
Show All Member Profiles 
Forum Statistics
Forums45
Topics47,513
Posts82,683
Average Daily Posts8
Members2,159
Most Online1,567
Apr 25th, 2010
Latest Postings
Top Posters(All Time)
UGN Security 40,677
Gremelin 7,195
§intå× 3,255
SilentRage 1,273
Ice 1,146
pergesu 1,136
Infinite 1,041
jonconley 955
Girlie 908
unreal 860
Top Liked Users (All Time)
§intå× Likes: 1
Cold Sunn Likes: 1
Crime Likes: 1
Cyrez Likes: 1
Ghost Likes: 1
Gremelin Likes: 4
Ice Likes: 1
unreal Likes: 1
Top Liked Users (30 Days)
No Data Found
Powered by UBB.threads™ PHP Forum Software 7.6.0
(Snapshot build 20160902)