将字符串2012-12-05字符串的年月日存在int变量中

 1 string str(2012-12-05)
 2 
 3 int year, month, day;
 4 
 5 //暴力赋值
 6 
 7 year = (str[0] - '0') * 1000 + (str[1] - '0') * 100;
 8 year += (str[2] - '0') * 10 + (str[3] - '0');
 9 month = (str[5] - '0') * 10 + (str[6] - '0');
10 day = (str[8] - '0') * 10 + (str[9] - '0');

 

posted @ 2014-03-09 15:18  向日葵的祈愿  阅读(159)  评论(0)    收藏  举报