Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: C++ super-basic help thread  (Read 716 times)

malimbar04

  • Bay Watcher
    • View Profile
C++ super-basic help thread
« on: January 01, 2011, 09:25:10 pm »

So I'm working through a book on C++ (C++ Primer Plus Fifth Edition by SAMS publishing), and after re-writing several dozen sample programs and making a few on my own for study purposes, I decided to try to write a program for which I am otherwise unprepared. Why? because it's fun, in the most dwarfy way. I chose the real_age programming challenge, as it seemed like I should be relatively close to understanding it. I haven't worked with classes at all, but that didn't seem like it's THAt important yet.

Then I realized I have no idea what i'm talking about. I don't even know if ctime is the name for the modern library, or if I have to use time.h (and if I do, do I miss some features? other C++ libraries I'm working with don't have the .h ending). I also couldn't find "time" in the index of my book, and the C++ reference website seems to assume you already know what you're doing.

so, how do I use the time library to list various times, and then how do I convert the difference into say, days? From there I can figure out the math to turn that into months and years and print it to a console.
Logged
No! No! I will not massacre my children. Instead, I'll make them corpulent on crappy mass-produced quarry bush biscuits and questionably grown mushroom alcohol, and then send them into the military when they turn 12...

lagging savant

  • Bay Watcher
  • Escaped Lunatic ... bah. I was never caught.
    • View Profile
Re: C++ super-basic help thread
« Reply #1 on: January 02, 2011, 03:59:35 am »

http://www.cplusplus.com/reference/clibrary/ctime/strftime/ . I just used this today to make a quick logger for the game I'm making. cplusplus.com is full of c++ awesomeness. To print the time to the console, you can use cout. Put the data into a string then , cout << string.
Logged

lordnincompoop

  • Bay Watcher
  • Allusionist
    • View Profile
Re: C++ super-basic help thread
« Reply #2 on: January 02, 2011, 05:44:56 am »

And FYI we have a Bay12Prog thread for this stuff.
Logged

Outcast Orange

  • Bay Watcher
  • [SOMETIMES_SQUID]
    • View Profile
    • The Outcast Orange
Re: C++ super-basic help thread
« Reply #3 on: January 02, 2011, 11:47:41 am »

EDIT:

Sorry you had to see that, I forgot what I was doing for a second there.
Logged
[7:53:55 PM] Armok, why did you demand that I don't eat you?
[7:54:34 PM] [Armok]: woooooo

Burried Houses - Platform Explorer Demo H - Cloud Scream