如何才能快速入坑 C/C++?曾经我也是抱着《C++ Primer 中文版》和《Effective C++ 中文版》。但是对于初学者,它们并不是最好的选择,这里推荐《C/C++学习指南》一本非常适合入门的指导书。分享学习时候写的代码。
C:\Users\LAILAI\Desktop>g++ --version
g++.exe (GCC) 4.7.0 20111220 (experimental)
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
C:\Users\LAILAI\Desktop>g++ filename.cpp
// filename.cpp
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
time_t convert(int year, int month, int day, int hour, int minute, int second) {
tm info = { 0 };
info.tm_year = year - 1900;
info.tm_mon = month - 1;
info.tm_mday = day;
info.tm_hour = hour;
info.tm_min = minute;
info.tm_sec = second;
time_t t = mktime(&info);
return t;
}
int main() {
time_t now = time(NULL);
printf("now: %d \n",(int) now); //1970-01-01 00:00:00 seconds: 1542110087
tm info = *localtime(&now);
int year = info.tm_year + 1900;
int month = info.tm_mon + 1;
int day = info.tm_mday;
int hour = info.tm_hour;
int minute = info.tm_min;
int second = info.tm_sec;
time_t start = convert(1994,1,10,0,0,0);
time_t end = convert(2016,10,13,0,0,0);
int diff = (int)(end - start);
int days = diff / (24 * 3600);
printf("%d\n", days);
system( "PAUSE ");
return 0;
}