UGN Security Forums
My ProfileMember DirectoryLogin
Search our ForumsView our FAQView our Site Rules
View our CalendarView our Active TopicsGo to our Main Page

UGN Security Store
 

Network Sites UGN Security, The GoNix Initiative, Elite Web Gamers, Back of the Web, EveryDay Helper, VNC Web Design & Development
Sponsored Links
Latest Postings
The History Thread...
by Gremelin
09/18/14 12:42 PM
Doom 3
by Cyrez
09/11/14 11:58 PM
Latest Reviews
Topic Options
Rate This Topic
#17439 - 03/02/04 05:08 PM Files...creating if one doesn't exist.
acid45 Offline
Junior Member

Registered: 12/19/03
Posts: 38
Loc: 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 06:26 PM Re: Files...creating if one doesn't exist.
acid45 Offline
Junior Member

Registered: 12/19/03
Posts: 38
Loc: canada
-_-*
Code:
nfbuf = saveout.rdbuf();
nfbuf->open(filename, fstream::out);
saveout<< name << endl;

Top
#17441 - 03/02/04 07:22 PM Re: Files...creating if one doesn't exist.
acid45 Offline
Junior Member

Registered: 12/19/03
Posts: 38
Loc: 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 06:08 PM Re: Files...creating if one doesn't exist.
SilentRage Offline
DollarDNS Owner

Registered: 03/04/02
Posts: 1273
Loc: 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 04:02 PM Re: Files...creating if one doesn't exist.
acid45 Offline
Junior Member

Registered: 12/19/03
Posts: 38
Loc: 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 05:22 PM Re: Files...creating if one doesn't exist.
SilentRage Offline
DollarDNS Owner

Registered: 03/04/02
Posts: 1273
Loc: 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 12:21 AM Re: Files...creating if one doesn't exist.
acid45 Offline
Junior Member

Registered: 12/19/03
Posts: 38
Loc: 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

Featured Member
Registered: 03/02/02
Posts: 136
Forum Stats
2148 Members
46 Forums
34728 Topics
69898 Posts

Max Online: 1567 @ 04/25/10 05:20 AM
Top Posters
UGN Security 27890
Gremelin 7193
§intå× 3255
SilentRage 1273
Ice 1146
pergesu 1136
Infinite 1041
jonconley 955
Girlie 908
unreal 860
Newest Members
Tim050, Gecko666, defghi795767, Devo60, ali
2148 Registered Users
Who's Online
0 registered (), 356 Guests and 255 Spiders online.
Key: Admin, Global Mod, Mod
Latest News


Donate
  Get Firefox!
Get FireFox!