第一章 开始
2014-02-28 10:57
357 查看
main() 缺省 return 0;
using namespace std; //告诉编译器要使用在名字空间std中声明的名字
条件提示符#ifndef
编译器使用-D选项定义预处理器常量:$CC -DDEBUG main.c
编译C++时,编译器自动定义__cplusplus
编译标准C:__STDC__ 记录已被编译行数:__LINE__ 正在被编译的文件名:__FILE__ __TIME__ __DATE__
通用预处理器宏assert(),判断一个必须的前提条件
注释对/*...*/不能嵌套,解决办法:加空格/*... * /
未知个数的输入值
文件输入和输出
0一般表示成功执行
-1一般表示不成功
比如你往数据库里插入一条数据,插入失败的时候你返回-1。
那么当你调用该方法时,返回了-1,你就知道:“哦,这是插入数据失败了”
using namespace std; //告诉编译器要使用在名字空间std中声明的名字
//使用vector对象 #include <vector> vector<string> chapter_titles(20);
条件提示符#ifndef
#ifndef BOOKSTROE_H #define BOOKSTORE_H //... #endif若前面没定义BOOKSTORE_H,则执行
int main(){ #ifdef DEBUG cout<<"Beginning execution of main()\n"; #endif //... }
编译器使用-D选项定义预处理器常量:$CC -DDEBUG main.c
编译C++时,编译器自动定义__cplusplus
#ifdef __cplusplus extern "C" #endif int min(int, int);
编译标准C:__STDC__ 记录已被编译行数:__LINE__ 正在被编译的文件名:__FILE__ __TIME__ __DATE__
通用预处理器宏assert(),判断一个必须的前提条件
#include <assert.h> assert(filename !=0);filename=0则终止程序
注释对/*...*/不能嵌套,解决办法:加空格/*... * /
未知个数的输入值
#include <iostream> #include <string> int main(){ string word; while(cin>>word) cout<<"word read is: "<<word<<'\n'; cout<<"ok: no more words to read: bye!\n"; return 0; }
文件输入和输出
#include <iostream> #include <fstream> #include <sting> int main(){ ofstream outfile("out_file"); ifstream infile("in_file"); if(!infile){ cerr<<"error: unable to open input file!\n"; return -1; } if(!outfile){ cerr<<"error: unable to open output file!\n"; return -2; } string word; while (infile>>word) outfile<<word<<' '; return 0; }根据所定义函数的需求返回不同的值。
0一般表示成功执行
-1一般表示不成功
比如你往数据库里插入一条数据,插入失败的时候你返回-1。
那么当你调用该方法时,返回了-1,你就知道:“哦,这是插入数据失败了”
相关文章推荐
- 第一章 开始编写FLTK程序
- OpenStack云计算口袋书-第一章-开始OpenStack之旅(二)
- C++ Primer | 第一章 开始
- 第一章 开始
- 基于SharePoint 工作流的InfoPath 2010的报修系统的建立:第一章 为什么不开始自己搞一个系统呢?
- 游戏设计的艺术:一本透镜的书——第一章 在最开始的时候,只有设计师
- 第二行代码学习笔记——第一章:开始启程——你的第一行Android代码
- C++ Primer 5 笔记 第一章 开始
- C++ Primer学习笔记 第一章 开始
- [HeadFrist-HTMLCSS学习笔记][第一章Web语言:开始了解HTML]
- [C++Primer] 第一章 开始 & 第一部分 C++ 基础
- 第一章 开始
- Spring in Action 学习笔记—第一章 开始Spring之旅(转贴)
- OpenStack云计算口袋书-第一章-开始OpenStack之旅(四)
- BlazeDS开发指南中文版第一章(开始BlazeDS试用之旅)
- [HeadFrist-HTMLCSS学习笔记][第一章Web语言:开始了解HTML]
- c++程序设计第一章 开始接触c++
- 2017.12.12 架构探险-第一章-从一个简单的web应用开始