Previous Thread
Next Thread
Print Thread
Rate Thread
Files...creating if one doesn't exist.
#17439 03/02/04 03:08 PM
Joined: Dec 2003
Posts: 38
acid45 Offline OP
Junior Member
OP Offline
Junior Member
Joined: Dec 2003
Posts: 38
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.

Re: Files...creating if one doesn't exist.
#17440 03/02/04 04:26 PM
Joined: Dec 2003
Posts: 38
acid45 Offline OP
Junior Member
OP Offline
Junior Member
Joined: Dec 2003
Posts: 38
-_-*
Code
nfbuf = saveout.rdbuf();
nfbuf->open(filename, fstream::out);
saveout<< name << endl;

Re: Files...creating if one doesn't exist.
#17441 03/02/04 05:22 PM
Joined: Dec 2003
Posts: 38
acid45 Offline OP
Junior Member
OP Offline
Junior Member
Joined: Dec 2003
Posts: 38
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.

Re: Files...creating if one doesn't exist.
#17442 03/03/04 04:08 PM
Joined: Mar 2002
Posts: 1,273
DollarDNS Owner
Offline
DollarDNS Owner
Joined: Mar 2002
Posts: 1,273
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
Re: Files...creating if one doesn't exist.
#17443 03/04/04 02:02 PM
Joined: Dec 2003
Posts: 38
acid45 Offline OP
Junior Member
OP Offline
Junior Member
Joined: Dec 2003
Posts: 38
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.

Re: Files...creating if one doesn't exist.
#17444 03/04/04 03:22 PM
Joined: Mar 2002
Posts: 1,273
DollarDNS Owner
Offline
DollarDNS Owner
Joined: Mar 2002
Posts: 1,273
so I take it you're not interested in the C solution?


Domain Registration, Hosting, Management
http://www.dollardns.net
Re: Files...creating if one doesn't exist.
#17445 03/12/04 10:21 PM
Joined: Dec 2003
Posts: 38
acid45 Offline OP
Junior Member
OP Offline
Junior Member
Joined: Dec 2003
Posts: 38
I have the C solution laugh 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 [censored]. Going out into the workforce next week laugh . 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.


Link Copied to Clipboard
Member Spotlight
SephiroX
SephiroX
England
Posts: 122
Joined: March 2002
Forum Statistics
Forums41
Topics33,680
Posts68,696
Average Daily Posts0
Members2,171
Most Online3,253
Jan 13th, 2020
Latest Postings
Animation,
by JohanKaariainen - 08/15/19 01:18 AM
Blackbeard.....
by Gremelin - 10/03/18 07:02 PM
my old account still exists!
by Crime - 08/10/18 02:47 PM
Okay WTF?
by HenryMiring - 09/27/17 01:45 AM
The History Thread...
by Gremelin - 08/11/17 12:11 PM
My friend NEEDS your HELP!
by Lena01 - 07/21/17 12:06 AM
I'm having fun with this guy.
by gabithompson730 - 07/20/17 01:50 AM
I want to upgrade my phone
by gabithompson730 - 07/20/17 01:49 AM
Doom 3
by Cyrez - 09/11/14 08:58 PM
Amazon Gift Card Generator/KeyGen?te
by Gecko666 - 08/22/14 09:21 AM
AIM scene 99-03
by lavos - 09/02/13 08:06 AM
Planetside 2
by Crime - 03/04/13 07:10 AM
Beta Testers Wanted
by Crime - 03/04/13 06:55 AM
Hello Everyone
by Gremelin - 02/12/12 06:01 PM
Tracfone ESN Generator
by Zanvin Green - 01/18/12 01:31 PM
Python 3 issue
by Testing - 12/17/11 09:28 PM
tracfone airtime
by Drache86 - 07/30/11 03:37 AM
Backdoors and the Infinite
by ZeroCoolStar - 07/10/11 03:52 AM
Where and how do you torrent?
by ZeroCoolStar - 07/06/11 07:22 AM
HackThisZIne #12 Releaseed!
by Pipat2 - 04/28/11 09:20 PM
gang wars? l33t-wars?
by Gremelin - 04/28/11 05:56 AM
Consolidate Forums
by diggin2deep - 04/21/11 10:02 AM
LAN Hacking Noob
by Gremelin - 03/12/11 12:42 AM
Top Posters
UGN Security 41,392
Gremelin 7,203
§intå× 3,255
SilentRage 1,273
Ice 1,146
pergesu 1,136
Infinite 1,041
jonconley 955
Girlie 908
unreal 860
Top Likes Received
Ghost 2
Ice 1
Dartur 1
Cyrez 1
Girlie 1
unreal 1
Powered by UBB.threads™ PHP Forum Software 7.7.4