[問題]螞蟻書範利一問 C程式設計藝術第五版

看板C_and_CPP作者 (forever)時間14年前 (2011/04/29 08:13), 編輯推噓0(005)
留言5則, 4人參與, 最新討論串1/2 (看更多)
source code如下: #include "stdafx.h" #include <stdio.h> #include <stdlib.h> enum months { Jan=1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec}; int _tmain(int argc, _TCHAR* argv[]) { enum months month; const char *monthName[]={" ", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; for ( month = Jan; month<=Dec; month++) { printf("%2d%15s\n", month, monthName[month]); } return 0; } 我翻了兩版的螞蟻書,都寫得一樣。可是...我實際操做出現error... 1>i:\project\enum_example_1\enum_example_1.cpp(19) : error C2676: binary '++' : 'months' does not define this operator or a conversion to a type acceptable to the predefined operatormonth++ 問題出在month++這個用法不行... 所以是書打錯了嗎????? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.118.199.117

04/29 16:19, , 1F
這是C語言的寫法,C++不能用
04/29 16:19, 1F

04/29 17:16, , 2F
用int month就好啦
04/29 17:16, 2F

04/29 21:47, , 3F
++不是遞增運算子嘛?? C不是也有這個運算子
04/29 21:47, 3F

04/29 21:48, , 4F
能不能幫我解個惑???
04/29 21:48, 4F

04/29 21:55, , 5F
樓上是? 0.0
04/29 21:55, 5F
文章代碼(AID): #1DkdD4El (C_and_CPP)
文章代碼(AID): #1DkdD4El (C_and_CPP)