Sign in to follow this  
Huangdi

ofstream help plz

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[i].URL; printf("\tURL = %s\n", s2?s2:"<NONE>"); Now what? "cached << *s2;" doesnt work...

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this