[轉錄][轉錄][C++] 上機考 (3)

看板NTUBIME100HW作者 (Pineapple)時間18年前 (2007/12/11 08:04), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
※ [本文轉錄自 NTUBIME99-HW 看板] 作者: matrixjimmy (Jimmy) 看板: NTUBIME99-HW 標題: [轉錄][C++] 上機考 (3) 時間: Sun Dec 17 14:48:24 2006 ※ [本文轉錄自 NTUBIME97-HW 看板] 作者: ychia (12/13~17 生機週!!) 看板: NTUBIME97-HW 標題: [C++] 上機考 (3) 時間: Wed Dec 8 00:21:31 2004 #include <iostream> using std::cout; using std::cin; using std::endl; #include <cstdlib> int main() { void reverseString( char [] ); unsigned int SIZE = 80; // 最多存幾個字元 char input[SIZE + 1]; cout << "請輸入一字串,輸入完畢按 Enter,程式將會 show 出相反的順序的字串" << endl; while ( cin.getline(input, SIZE + 1, '\n') ) reverseString( input ); return 0; } void reverseString( char string[] ) { int count = 0; int i; for ( i = 0; string[ i ] != '\0'; i++) count++; for ( i = count - 1; i >= 0; i--) cout << string[ i ]; cout << endl; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.22.100

140.112.239.56 12/08,
char input[SIZE + 1] 好像要換成81才行괠
140.112.239.56 12/08

140.112.239.56 12/08,
可是我的C++程式一向有問題
140.112.239.56 12/08
-- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.62.101.203

12/17 17:48,
cin.getline(input, SIZE + 1, '\n')這條程式碼是何意思?
12/17 17:48

12/18 21:26,
陣列名稱,陣列大小,將一行字串讀入 包含\n ,然後捨棄\n
12/18 21:26

12/18 21:27,
我說...其實...搜尋引擎真的很好用...
12/18 21:27

12/18 21:51,
什麼叫做"包含再捨棄"??
12/18 21:51

12/19 20:33,
事實上就是讀到\n就停止,不繼續讀取
12/19 20:33

12/19 22:32,
cin input這個變數 最大接收80 遇到enter('\n')就開始跑
12/19 22:32
-- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.241.52
文章代碼(AID): #17NTFxOg (NTUBIME100HW)