C++ Program Structure (and tools).ppt
《C++ Program Structure (and tools).ppt》由会员分享,可在线阅读,更多相关《C++ Program Structure (and tools).ppt(15页珍藏版)》请在麦多课文档分享上搜索。
1、C+ Program Structure (and tools),Today well talk generally about C+ development (plus a few platform specifics) Well develop, submit, and grade code in Windows Its also helpful to become familiar with Linux E.g., on shell.cec.wustl.edu For example, running code through two different compilers can ca
2、tch a lot more “easy to make” errors,Writing a C+ Program,C+ source files (ASCII text) .cpp,Programmer (you),emacs,editor,C+ header files (ASCII text) .h,1 source file = 1 compilation unit,Also: .C .cxx .cc,Also: .H .hxx .hpp,readme (ASCII text),Eclipse,Visual Studio,What Goes Into a C+ Program?,Dec
3、larations: data types, function signatures, classes Allows the compiler to check for type safety, correct syntax Usually kept in “header” (.h) files Included as needed by other files (to keep compiler happy)class Simple typedef unsigned int UINT32; public:Simple (int i); int usage (char * program_na
4、me);void print_i (); private: struct Point2D int i_; double x_; ; double y_;Definitions: static variable initialization, function implementation The part that turns into an executable program Usually kept in “source” (.cpp) filesvoid Simple:print_i () cout “i_ is ” i_ endl; Directives: tell compiler
5、 (or precompiler) to do something More on this later,A Very Simple C+ Program,#include / precompiler directiveusing namespace std; / compiler directive/ definition of function named “main” int main (int, char *) cout “hello, world!” endl;return 0; ,What is #include ?,#include tells the precompiler t
6、o include a file Usually, we include header files Contain declarations of structs, classes, functions Sometimes we include template definitions Varies from compiler to compiler Advanced topic well cover later in the semesteris the C+ label for a standard header file for input and output streams,What
7、 is using namespace std; ?,The using directive tells the compiler to include code from libraries that have separate namespaces Similar idea to “packages” in other languages C+ provides a namespace for its standard library Called the “standard namespace” (written as std) cout, cin, and cerr standard
8、iostreams, and much more Namespaces reduce collisions between symbols Rely on the : scoping operator to match symbols to them If another library with namespace mylib defined cout we could say std:cout vs. mylib:cout Can also apply using more selectively: E.g., just using std:cout,What is int main (i
9、nt, char*) . ?,Defines the main function of any C+ program Who calls main? The runtime environment, specifically a function often called something like crt0 or crtexe What about the stuff in parentheses? A list of types of the input arguments to function main With the function name, makes up its sig
10、nature Since this version of main ignores any inputs, we leave off names of the input variables, and only give their types What about the stuff in braces? Its the body of function main, its definition,Whats cout “hello, world!” endl; ?,Uses the standard output iostream, named cout For standard input
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- CPROGRAMSTRUCTUREANDTOOLSPPT
