[SOLVED] What's the best way to write strings to text files?

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
Bullet Pulse
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 89
Joined: Sun Feb 21, 2010 6:25 pm

[SOLVED] What's the best way to write strings to text files?

Post by Bullet Pulse »

I would like to use something like fprintf(), but I can't send a string as the 2nd parameter, as it takes a const char*.
I don't have much experience with writing to text files, and I'm just trying to make a simple program that accepts a string,
manipulates that string, and then writes that string to a text file.

Thanks.
Last edited by Bullet Pulse on Mon Mar 08, 2010 5:24 pm, edited 1 time in total.
Image
User avatar
Bakkon
Chaos Rift Junior
Chaos Rift Junior
Posts: 384
Joined: Wed May 20, 2009 2:38 pm
Programming Language of Choice: C++
Location: Indiana

Re: What's the best way to write strings to text files?

Post by Bakkon »

If you're working with a string and something requires a char*, you can use the c_str() method of your string object.
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: What's the best way to write strings to text files?

Post by avansc »

Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
User avatar
Bakkon
Chaos Rift Junior
Chaos Rift Junior
Posts: 384
Joined: Wed May 20, 2009 2:38 pm
Programming Language of Choice: C++
Location: Indiana

Re: What's the best way to write strings to text files?

Post by Bakkon »

avansc wrote:edit: DAMN YOU!!!
:-*
User avatar
short
ES Beta Backer
ES Beta Backer
Posts: 548
Joined: Thu Apr 30, 2009 2:22 am
Current Project: c++, c
Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
Programming Language of Choice: c, c++
Location: Oregon, US

Re: What's the best way to write strings to text files?

Post by short »

hahaha bakkon won this time :P :mrgreen:
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
User avatar
Bullet Pulse
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 89
Joined: Sun Feb 21, 2010 6:25 pm

Re: What's the best way to write strings to text files?

Post by Bullet Pulse »

Thanks everyone. I made a program to use this and it works. :)
Image
Post Reply