Presentation is loading. Please wait.

Presentation is loading. Please wait.

簡易 Visual Studio 2010 C++ 使用手冊

Similar presentations


Presentation on theme: "簡易 Visual Studio 2010 C++ 使用手冊"— Presentation transcript:

1 簡易 Visual Studio 2010 C++ 使用手冊
Han-Chern Ling

2 下載 Visual Studio 2010 中文版 利用瀏覽器IE進入學校計算機網路中心 http://www.cc.ncku.edu.tw
點選校園授權軟體,或 進入『Visual Studio 系列』,其中有許多版本,請下載 『Visual Studio 2010 中文專業版』的影像檔,然後利用光碟軟體燒錄成光碟,或利用虛擬光碟軟體載入影像檔。

3 成大的電腦資源 http://www.cc.ncku.edu.tw/download
成大電腦資源僅在成大校園網路中才可下載使用,若在校園外網路系統(如Hinet等),需先設定Proxy伺服器;設定時,先在IE選單中 工具 – Internet 選項 – 連線,點選「區域網路設定」按鈕,如左圖。 在Proxy伺服器設定部份,點選「使用Proxy伺服器」,並填入網址為  rpa.lib.ncku.edu.tw及連接埠3128, 如右圖。

4 成大的電腦資源 http://www.cc.ncku.edu.tw/download
計網中心已建置「TWAREN SSL VPN服務」,方便老師及學生在校外也可以使用學校的網路資源。一旦在家中電腦安裝此服務後,就如同在校園內一樣使用電子期刊、校園授權軟體等服務。詳細說明請見計網中心網頁 SSL VPN服務,或下載說明文件:

5 安裝 Visual Studio 2010 中文版 安裝結束後,建議把「開始」中「程式集」的 「Microsoft Visual Studio 2010」 及 「Visual Studio 命令提示字元」這兩個捷徑複製到桌面。

6 建立、編譯、執行 C 程式 兩種方式: 進入Microsoft Visual Studio 2010後,先建立專案(Project) ;或
在Visual Studio命令提示字元(DOS 視窗)中執行 cl xxx.c

7 在Studio 2010 中建置新的 Project (專案) - 1
第一次執行 Studio 2010 時,程式會先要求選擇預設環境設定,點選『Visual C++ 開發設定』,再點選啟動Visual Studio。過一陣子,就會出現右下圖之畫面。

8 在Studio 2010 中建置新的 Project (專案) - 2
在 Studio 2010 中必須要先建立程式專案 Project 後,才可進行後續的編譯程式與執行,故在此先進行建立 Project : 進入Visual C 後  檔案  新增  專案; 出現『新增專案視窗』後,選取『一般』『空專案』; 選取本project 存取位置後,在名稱處填入專案名稱,例如『Project01』 按確定後,這就建好ㄧ個新的專案了。

9 在Studio 2010 中建置新的 Project (專案) - 3
接下來,就要建立新的 C 或 C++ 的程式碼(source code),或將已建好的 source code 加入專案中 : 建立新的 C 或 C++ 的程式碼 方案總管(滑鼠右鍵)  原始程式檔 加入  新增項目; 出現『加入新項目』  程式碼  C++檔  加入名稱(如果是C的程式檔,請強制使用副檔名 .c,否則預設副檔名是 .cpp)  加入; 這時就可在新視窗鍵入你的程式碼。 開啟已建立的 C 或 C++ 的程式碼 方案總管(滑鼠右鍵)  原始程式檔 加入  現有項目

10 在Studio 2010 中建置新的 Project (專案) - 4
Visual Studio 2010 在執行程式時,程式執行結束後會立刻關閉視窗,所以必須要在主函數最後,「return 0;」前一行加入 system(“pause”); 以及在程式前面加入 #include <stdlib.h> 以免無法看到執行結果。 但在 Studio 2005 或 2008 版本就不需這兩行。

11 在Studio 2010 中編譯及執行 Project (專案) - 5
程式碼完成後,就可建立執行檔了: 建置  建置方案 (or Press F7)  開始編譯(希望編譯時沒有出現錯誤) 偵錯  啟動但不偵錯 (or Press ctrl+F5)  點選此處來執行程式

12 方法二:直接在 DOS 視窗下、下指令碼 \> cl source.c
如果安裝的是 Visual Studio 2010 的版本,請用該版本專用的命令提示字元(在開始  Microsoft Visual Studio 2010  Visual Studio Tools  Visual Studio 2010 命令提示字元),不要使用附屬應用程式下的命令提示字元。你可將該『Visual Studio 2010 命令提示字元』複製到桌面。 方便、簡潔;但Debugging ? 需預先利用 Text Editor (如記事本) 編輯程式

13 簡易DOS操作指令 DOS 是 Disk Operation System 的簡稱,是早期(1985~1995) Microsoft 在個人電腦上發展的批次作業系統,只能使用文字指令來操作電腦。自從視窗系統出現後,DOS就成視窗系統下的一個應用程式。下述是本課程可能用到的DOS指令。 > cd .. :進入上一層目錄 > cd\ :到根目錄 > D: :到磁碟機D槽的根目錄 > cd temp :進入temp 檔案夾中 > dir :列出檔案夾中檔案名稱 > help dir :觀看詳細的 dir 指令 > cl xxxx.c :將 xxxx.c 的程式碼編譯連結成執行檔 xxxx.exe > del xxxx.exe :刪除名稱為 xxxx.exe 的檔案 > md project :建立新目錄 project > rd project :刪除空的資料夾 project > deltree project :刪除資料夾 project以及資料夾 project 中所有內容

14 Oops! 錯誤產生時,該怎麼辦? Syntax Errors (語法錯誤) – When compiler can not recognize a statement If an error message appears in the Output pane’s Build tab, double-clicking anywhere on the error message displays the source file and places a blue arrow marker in the margin indicator bar (i.e., the gray strip to the left of the source code), indicating the offending line. If you do not understand the error message, highlight the error message number by dragging the mouse over the number, then press the F1 key. This displays a help file that provides information about the error and some helpful hints as to the cause of the error.

15 Debugging Run-Time Logic Errors (語意錯誤)
The Visual Studio provides a debugger tool to help the programmer find run-time logic errors in programs that compile and link successfully but do not produce expected results. The debugger lets the programmer view the executing program and its data as the program runs either one step at a time or at full speed. The program stops on a selected line of code or upon a fatal run-time error. To use the debugger, set one or more breakpoints by clicking the line in the program where the breakpoint is to be placed and clicking the Insert/Remove Breakpoint button in the Build MiniBar or by pressing the F9 key.

16 Debugging Run-Time Logic Errors
The Visual Studio provides a debugger tool to help the programmer find run-time logic errors in programs that compile and link successfully but do not produce expected results. The debugger lets the programmer view the executing program and its data as the program runs either one step at a time or at full speed. The program stops on a selected line of code or upon a fatal run-time error. To use the debugger, set one or more breakpoints by clicking the line in the program where the breakpoint is to be placed and clicking the Insert/Remove Breakpoint button in the Build MiniBar or by pressing the F9 key.

17 Debugging You may need to manually switch between the IDE and the console window to perform input. To switch between windows you can use Alt + Tab or click your program’s panel on the Windows taskbar at the bottom of the screen. The yellow arrow to the left of a statement indicates that execution is suspended at this line. This statement will be the next statement executed.


Download ppt "簡易 Visual Studio 2010 C++ 使用手冊"

Similar presentations


Ads by Google