Your browser does not seem to support CSS. If images appear below, please disregard them.
toggle
May
S M T W T F S
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Sponsored Links
Latest Postings
Topic Options
Rate This Topic
#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.

Top
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;

Top
#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.

Top
#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
Top
#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.

Top
#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
Top
#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.

Top

Member Spotlight
Gremelin

Gremelin
Portland, OR; USA
Posts: 7,194
Joined: February 2002
Show All Member Profiles 
Forum Statistics
Forums46
Topics45,741
Posts80,909
Members2,157
Most Online1,567
Apr 25th, 2010
Top Posters(All Time)
UGN Security 38,905
Gremelin 7,194
§intå× 3,255
SilentRage 1,273
Ice 1,146
pergesu 1,136
Infinite 1,041
jonconley 955
Girlie 908
unreal 860
Newest Members
Herbert_Sherbert, codemauve, Lillysdragon1984, Brewwit, boa
2157 Registered Users
Who's Online Now
0 registered members (), 2 guests and 3 spiders.
Latest News