"Thinkinginc++" 42, the const in the class

Source: Internet
Author: User
Tags month name

The const is initialized in the place where it was established. The const modifier cannot be modified.
About the static const type is: All objects are shared and unchanging data.
http://blog.csdn.net/luoweifu/article/details/20288549
Output local time:
    time_t t = time (0);    Char tmp[64];    Strftime (TMP, sizeof (TMP), "%y/%m/%d%x%A year%j days%z", LocalTime (&t));cout<<tmp;



size_t strftime (char *strdest, size_t maxsize, const char *format, const struct TM *timeptr);
Generates a string based on a format string.
struct TM *localtime (const time_t *timer);
Get local time, LocalTime gets the results returned by the Fabric TM
The returned string can be in the following format:
%a abbreviation of the week. Eg:tue
%A the full name of the week. Eg:tuesday
The abbreviation for the%b month name.
The full name of the%B month name.
The%c local end datetime is a better representation of the string.
%d numbers indicate the day ordinal of the month (range 00 to 31). Date
The%H uses a 24-hour number to denote the number of hours (ranging from 00 to 23).
%I A 12-hour number indicates the number of hours (range 01 to 12).
%j indicates the day of the Year in Numbers (range 001 to 366).
Number of%m months (range from 1 to 12).
%M minutes.
%p indicates local time with ' AM ' or ' PM '.
%s Number of seconds.
The number of%u is expressed as the week of the current year, and the first one weeks start in Sunday.
The%W number is expressed as the week of the current year, and the first one weeks start in Monday.
%w numbers indicate the day of the week (0 is Sunday).
%x does not include date notation for time.
%x does not include a time representation of the date. Eg:15:26:30
The%y two digits represent the year (range from 00 to 99).
%Y a full year number representation, that is, four digits. eg:2008
%Z (%Z) time zone or name abbreviation. EG: China Standard Time
Percent% character.







Scenario Two advantages: can be accurate to the millisecond level; Cons: Using the Windows API
#include <windows.h> #include <stdio.h>int main (void) {SYSTEMTIME sys; Getlocaltime (&sys); printf ("%4d/%02d/%02d%02d:%02d:%02d.%0 3d Week%1d\n ", Sys.wyear,sys.wmonth,sys.wday,sys.whour,sys.wminute, Sys.wsecond,sys.wmilliseconds,sys.wdayofweek);  return 0;}



Scenario three, advantages: using System functions, can also modify the system time
This file must be a C + + file
#include <stdlib.h> #include <iostream>using namespace std;void main () {    system ("Time");}



Scenario four, convert the current time to a second level, and then the corresponding time conversion can be
This file must be a C + + file
#include <iostream> #include <ctime>using namespace Std;int main () {time_t now_time; now_time = time (NULL); cout<<now_time; return 0;}






Srand and Rand () work together to produce a sequence of pseudo-random numbers.
The RAND function requires a system-supplied seed to generate a sequence of pseudo-random numbers before generating a random number, and Rand produces a series of random numbers based on the value of the seed. If the seed provided by the system does not change, the sequence of pseudo-random numbers generated by each call to the RAND function is the same.

Srand (unsigned seed) alters the seed value provided by the system through the parameter seed, which allows the sequence of pseudo-random numbers generated by each call to the RAND function to be different, thus achieving a true "random" meaning.




/*** book: "thinkinginc++" * Function: const* time in class: September 8, 2014 15:39:57*/#include <iostream>using namespace Std;class fred{    const int size;//class inside the Constpublic:    Fred (int sz);   constructors, etc., are used to initialize the const    void print ();}; fred::fred (int sz): size (SZ) {}void Fred::p rint () {Cout<<size<<endl;} int main () {    Fred A (1), B (2), C (3);    A.print (), B.print (), C.print ();    This is the first time I have seen you can use "," to separate    return 0;



"Thinkinginc++" 42, the const in the class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.