Jump to content
  • Advertisement
Sign in to follow this  
Huangdi

ofstream help plz

This topic is 5135 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I need to display the contents of pointer s2 into the file data.txt: std::ofstream cached ("data.txt"); const char *s2 = r._return.resultElements.__ptr.URL; printf("\tURL = %s\n", s2?s2:"<NONE>"); Now what? "cached << *s2;" doesnt work...

Share this post


Link to post
Share on other sites
Advertisement

Assuming s2 is a properly null-terminated C-style string, this should work: cached << s2;

Share this post


Link to post
Share on other sites
Quote:
Original post by Thunder_Hawk
What do you mean by "doesn't work"? Assuming that s2 is a properly null-terminated string, there should be no problem.
The way he has it puts the first character of the string.

Share this post


Link to post
Share on other sites
Quote:
Original post by xtrmntr
Wouldn't it put the first character of s2 in the file?
Yeah, my mistake. [wink]
Quote:
Original post by Huangdi
wait... what do u mean by null terminated?
A \0 char at the end. Any string with double quotes (") will be null-terminated, eg const char * moo = "This is a null-terminated string.";

Share this post


Link to post
Share on other sites
Quote:
Original post by Ra
Quote:
Original post by Thunder_Hawk
What do you mean by "doesn't work"? Assuming that s2 is a properly null-terminated string, there should be no problem.
The way he has it puts the first character of the string.


lol...My eyes are starting to get to me. [wink]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!