ofstream help plz

Started by
7 comments, last by FireNet 19 years, 7 months ago
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...
Advertisement

Assuming s2 is a properly null-terminated C-style string, this should work: cached << s2;
Ra
What do you mean by "doesn't work"? Assuming that s2 is a properly null-terminated string, there should be no problem.
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
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.
Ra
EDIT: NM, works now! Thx :) I felt kinda stupid... wtf lol.... haven't programmed in a while...
Wouldn't it put the first character of s2 in the file?
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.";
Ra
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]
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
Try this tutorial, it covers the fstream file i/o quite well.

Fstream Tutorial

Helps ?
______________________________________________________________________________________________________
[AirBash.com]

This topic is closed to new replies.

Advertisement