Jump to content
  • Advertisement
Sign in to follow this  

Using ctime() and ofstream, wipes text after ctime()

This topic is 2932 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

code explains more than my words ever will,

void File::Write(const char* stuff)
time_t *newTime;time(newTime);

the class File has a ofstream OutFile...

so if i use File::Write("lol");

it will wipe everything after the ">" character... i have no clue why.

Share this post

Link to post
Share on other sites
It may be because you are sending a ptr to time(...) that doesn't point to any valid storage memory, so time just overwrites that unallocated memory.

time_t new_time; time(&new_time); // is one way to go.

then, ... << ctime(&new_time) << ...

Share this post

Link to post
Share on other sites
One way is to populate a struct tm, then use the tm_sec field.

See 'man localtime' if you are on a posix system.

There are other (probably better ways to do this), but ->

time_t t1 = time(0);
struct tm *t = localtime(&t1);

cout << t->tm_sec;

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!