c++的基本知识

c++的基本知识
      1. C++虽然主要是以C的基础发展起来的一门新语言,但她不是C的替代品,不是C的升级,C++和C是兄弟关系。没有谁比谁先进的说法,更重要的一点是C和C++各自的标准委员会是独立的,最新的C++标准是C++98,最新的C标准是C99。因此也没有先学C再说C++的说法,也不再(注意这个"不再")有C++语法是C语法的超集的说法。
  2. C++/CLI 和 C# 是微软的,它们与C和C++没有任何关系,虽然部分语法相似。但哪两种语言不相似呢?都是abc这26个字母。
  3. 不要使用TC/TC++/BC/CB等古老的编译器来学习C/C++,因为它们太古老了,不支持新的C/C++标准。不要使CBX/VC++6.0/VC2005等对C/C++标准支持不好的编译器,虽然这些编译器适合工作,但不适合学习,因为它们中的语法陷阱很多。记住唯一适合学习的编译器是 gcc/mingw。
  4. 不要用""代替<>来包含系统头文件,虽然有些编译器允许你这样做,但它不符合C/C++标准。错误的示例#include "stdio.h",#include "iostream"
  5. 不要将main函数的返回类型定义为void,虽然有些编译器允许你这样做,但它不符合C/C++标准。不要将函数的int返回类型省略不写,在C++中要求编译器至少给一个警告。错误的示例:void main() {},main() {}
  6. 不要把VC++中的 #include "stdafx.h" 贴出来,它是预编译头文件。如同上菜时不要把厨师也放到托盘中。
  7. [C++]不要#include <iostream.h>,不要#include<string.h>,因为它们已经被C++标准明确的废弃了,请改为 #include <iostream> 和 #include < cstring>。
  规则就是:
  a. 如果这个头文件是旧C++特有的,那么去掉.h后缀,并放入std名字空间,比如 iostream.h 变为 iostream。
  b. 如果这个头文件是C也有的,那么去掉.h后缀,增加一个c前缀,比如 string.h 变为 cstring、stdio.h 变为 cstdio, 等等。
BTW:不要把<string.h>、<cstring>、<string>三个头文件搞混淆
BTW:windows.h不是C/C++的标准文件,因此它的命名C/C++不管。
  8. 不要再写 char* p = "XXX" 这种语句,要写成 const char* p = "XXX",编译器之所以让前者通过编译是为了兼容以前的大量的旧代码。  
  BTW:const TYPE* p 和 TYPE const* p 是一样的,风格不同而已。
  BTW:C语言中也有const关键字。
   9. 不要在同一条语句中包含一个变量的多个++/--,因为它们的解析在C/C++标准中没有规定,完全取决于编译器的个人行为。
  10. C/C++是平台无关性语言,因此系统相关的process/GUI等不在标准C/C++库中。比如 graphics.h和windows.h等是由某个编译器提供的,而不是由C/C++提供的。
  11. C/C++只是语言,而且是平台无关性语言。
  论坛上有部分人甚至认为C就是dos,C++就是windows,那么请问linux是什么?
  12. [C++]面向对象曾经是设计c with class(C++的前身)的主要目的,但C++不是,C++是一个多典范语言。主要支持过程调用、基于对象、面向对象、泛式编程 这四种编程典范,当然还支持functional, generative,meta programming等典范。
  13. 语法学家不是文学家,所以当你学会了一门计算机语言时,你还需要学习数据机构和算法,还需要掌握工具和平台API的用法。
  14. C/C++是通用语言,因此语法很复杂,你应当裁减成适合你自己的语法集合,比如裁减成better C和ADT。
  15. C/C++是通用语言,因此只含通用的库,你应该丰富自己需要的库,比如汽车工业协会有自己的C/C++函数/类/模板库。
/
C/C++头文件一览
#include <assert.h>    //设定插入点
#include <ctype.h>     //字符处理
#include <errno.h>     //定义错误码
#include <float.h>     //浮点数处理
#include <fstream.h>    //文件输入/输出
#include <iomanip.h>    //参数化输入/输出
#include <iostream.h>   //数据流输入/输出
#include <limits.h>    //定义各种数据类型最值常量
#include <locale.h>    //定义本地化函数
#include <math.h>     //定义数学函数
#include <stdio.h>     //定义输入/输出函数
#include <stdlib.h>    //定义杂项函数及内存分配函数
#include <string.h>    //字符串处理
#include <strstrea.h>   //基于数组的输入/输出
#include <time.h>     //定义关于时间的函数
#include <wchar.h>     //宽字符处理及输入/输出
#include <wctype.h>    //宽字符分类
//
标准 C++ (同上的不再注释)
#include <algorithm>    //STL 通用算法
#include <bitset>     //STL 位集容器
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>     //复数类
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>      //STL 双端队列容器
#include <exception>    //异常处理类
#include <fstream>
#include <functional>   //STL 定义运算函数(代替运算符)
#include <limits>
#include <list>      //STL 线性列表容器
#include <map>       //STL 映射容器
#include <iomanip>
#include <ios>       //基本输入/输出支持
#include <iosfwd>     //输入/输出系统使用的前置声明
#include <iostream>
#include <istream>     //基本输入流
#include <ostream>     //基本输出流
#include <queue>      //STL 队列容器
#include <set>       //STL 集合容器
#include <sstream>     //基于字符串的流
#include <stack>      //STL 堆栈容器    
#include <stdexcept>    //标准异常类
#include <streambuf>    //底层输入/输出支持
#include <string>     //字符串类
#include <utility>     //STL 通用模板类
#include <vector>     //STL 动态数组容器
#include <cwchar>
#include <cwctype>
using namespace std;
//
C99 增加
#include <complex.h>   //复数处理
#include <fenv.h>    //浮点环境
#include <inttypes.h>  //整数格式转换
#include <stdbool.h>   //布尔环境
#include <stdint.h>   //整型环境
#include <tgmath.h>   //通用类型数学宏
 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
该资源不适合C、C++初学者,可作为C++高手向大师级进化的参考书。 内容: ... 17 Library introduction 17.1 General 17.2 The C standard library 17.3 Definitions 17.4 Additional definitions 17.5 Method of description (Informative) 17.6 Library-wide requirements 18 Language support library 18.1 General 18.2 Types 18.3 Implementation properties 18.4 Integer types 18.5 Start and termination 18.6 Dynamic memory management CONTENTS v c ISO/IEC N3000=09-0190 18.7 Type identification 18.8 Exception handling 18.9 Initializer lists 18.10Other runtime support 19 Diagnostics library 456 19.1 General 19.2 Exception classes 19.3 Assertions 19.4 Error numbers 19.5 System error support 20 General utilities library 20.1 General 20.2 Requirements 20.3 Utility components 20.4 Compile-time rational arithmetic 20.5 Tuples 20.6 Metaprogramming and type traits 20.7 Function objects . 520 20.8 Memory 541 20.9 Time utilities 583 20.10Date and time functions 596 20.11Class type_index 596 21 Strings library 599 21.1 General 599 21.2 Character traits 599 21.3 String classes 605 21.4 Class template basic_string 608 21.5 Numeric Conversions 635 21.6 Null-terminated sequence utilities . 636 22 Localization library 640 22.1 General 640 22.2 Header <locale> synopsis 640 22.3 Locales 641 22.4 Standard locale categories . 653 22.5 Standard code conversion facets 693 22.6 C Library Locales 695 23 Containers library 696 23.1 General 696 23.2 Container requirements 696 23.3 Sequence containers 719 23.4 Associative containers . 758 23.5 Unordered associative containers . 776 24 Iterators library 791 24.1 General 791 24.2 Iterator requirements 791 CONTENTS vi c ISO/IEC N3000=09-0190 24.3 Header <iterator> synopsis 796 24.4 Iterator primitives 799 24.5 Iterator adaptors . 802 24.6 Stream iterators . 816 25 Algorithms library 825 25.1 General 825 25.2 Non-modifying sequence operations 835 25.3 Mutating sequence operations 839 25.4 Sorting and related operations 848 25.5 C library algorithms 862 26 Numerics library 864 26.1 General 864 26.2 Numeric type requirements . 864 26.3 The floating-point environment 865 26.4 Complex numbers 866 26.5 Random number generation . 876 26.6 Numeric arrays 920 26.7 Generalized numeric operations 940 26.8 C Library 944 27 Input/output library 949 27.1 General 949 27.2 Iostreams requirements . 950 27.3 Forward declarations 950 27.4 Standard iostream objects 952 27.5 Iostreams base classes . 954 27.6 Stream buffers 972 27.7 Formatting and manipulators 982 27.8 String-based streams 1009 27.9 File-based streams 1021 28 Regular expressions library 1036 28.1 General 1036 28.2 Definitions 1036 28.3 Requirements 1037 28.4 Header <regex> synopsis 1039 28.5 Namespace std::regex_constants 1045 28.6 Class regex_error 1048 28.7 Class template regex_traits 1048 28.8 Class template basic_regex 1051 28.9 Class template sub_match 1056 28.10Class template match_results 1062 28.11Regular expression algorithms 1066 28.12Regular expression Iterators . 1070 28.13Modified ECMAScript regular expression grammar 1076 29 Atomic operations library 1079 29.1 General 1079 29.2 Header <atomic> synopsis 1079 CONTENTS vii c ISO/IEC N3000=09-0190 29.3 Order and Consistency . 1082 29.4 Lock-free Property 1084 29.5 Atomic Types 1085 29.6 Operations on Atomic Types 1094 29.7 Flag Type and Operations 1098 29.8 Fences . 1099 30 Thread support library 1101 30.1 General 1101 30.2 Requirements 1101 30.3 Threads 1102 30.4 Mutual exclusion . 1107 30.5 Condition variables 1121 30.6 Futures 1129 A Grammar summary 1149 A.1 Keywords 1149 A.2 Lexical conventions 1149 A.3 Basic concepts 1154 A.4 Expressions . 1154 A.5 Statements . 1158 A.6 Declarations . 1159 A.7 Declarators . 1162 A.8 Classes . 1164 A.9 Derived classes 1165 A.10 Special member functions 1165 A.11 Overloading . 1165 A.12 Templates 1166 A.13 Exception handling 1167 A.14 Preprocessing directives 1167 B Implementation quantities 1169 C Compatibility 1171 C.1 C++ and ISO C 1171 C.2 Standard C library 1181 D Compatibility features 1185 D.1 Increment operator with bool operand . 1185 D.2 static keyword . 1185 D.3 Access declarations 1185 D.4 Implicit conversion from const strings . 1185 D.5 register keyword 1185 D.6 C standard library headers . 1185 D.7 Old iostreams members 1186 D.8 char* streams 1187 D.9 Binders 1196 D.10 auto_ptr 1198 E Cross references 1201 Index 1218 CONTENTS viii ISO/IEC N3000=09-0190 Index of Grammar Productions 1243 Index of Library Names 1246 Index of Implementation Defined Behavior 1280
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值