这是一个C++编程的简单教程,只有一页,基本涵盖了所有的内容(这是夸张)。不过,有功夫看看这么短的东西也好,也是一个比较好的参考文献。下面给出了第一章,就是一个比较罗嗦的目录。
You may copy this file for noncommercial use. The latest version is located at cs.fit.edu/~mmahoney/cse2050/how2cpp.html updated Sept. 26, 2005. Please report errors to Matt Mahoney at mmahoney@cs.fit.edu. Seldom-used features have been deliberately omitted.
Language Summary
Statements if, for, while, return, break...
Expressions arithmetic, comparison, assignment...
The most important types are int, char, bool, double, and the containers string, vector, and map. Summary of common types:
Built-in DescriptionThe following standard library types and functions require at the beginning of the program:
int x; Fastest integer type (16-32 bits), also short, long, unsigned
char x; 8-bit character, '\0' to '\xFF' or -128 to 127
double x; 64 bit real + or - 1.8e308, 14 significant digits, also float
bool x; true or false
Modifiers Description
const T x; Non-modifiable object
T& y=x; Reference, y is an alias for x, which both have type T
T f(...) {...} Defines f as a function returning T
T* p; Pointer to T (*p is a T object)
T[N] a; Array of N elements of T, a[0] to a[N-1]
static T x; Place x in data segment
register T x; (rare) Hint to optimize for speed
volatile T x; (rare) x may be modified externally
#include <header>
using namespace std;
Library Type Description Header
istream Standard input (cin) iostream
ostream Output (cout, cerr, clog) iostream
ifstream Input file fstream
ofstream Output file fstream
string Sequence of char string
vectorExpandable array/stack of T vector
dequeArray/double ended queue deque
listList/stack/queue of T list
mapAssociative mapping of T1 to T2 map
setA map with keys only set
pairTwo objects of type T1 and T2 map or utility
priority_queueSorted queue queue
stackStack stack
bitsetArray of N bool with logical operations bitset
valarrayArray with arithmetic operations valarray
complexComplex number complex
iterator Pointer into a container (Included with container)
const_iterator Pointer not allowing element assignment (Included with container)
exception Hierarchy of exception types stdexcept, exception
C++ Standard Library Functions Header
min(), max(), swap(), sort(), copy(), equal() algorithm
accumulate(), inner_product() numeric
back_inserter() iterator
equal_to(), less(), bind2nd() functional
set_new_handler() new
C Library Functions Header
atoi(), atof(), abs(), rand(), system(), exit() cstdlib
isalpha(), isdigit(), tolower(), toupper() cctype
sqrt(), log(), exp(), pow(), sin(), cos(), atan() cmath
clock(), time() ctime
strlen(), memset(), memmove(), memcmp() cstring
printf(), fopen(), getc(), perror() cstdio
assert() cassert
C++ allows you to create your own types and libraries. The most important type is a class, allowing object oriented programming. A class is an abstract data type with a hidden representation and a set of public member functions and types. Classes can be organized into a hierarchy (inheritance), and you can write code that accepts any type in this hierarchy (polymorphism). Functions and classes can be parameterized by type (templated).
class T {...}; Defines T as a collection of types, objects, and member functions
template... Defines a set of functions or classes over all T
typedef T U; Defines type U is a synonym for T
enum T {...}; Defines T as an int, and set of int constants
struct T {...}; Like a class, except default scope of members is public
union T {...}; A struct with object members overlapping in memory
namespace N {...}; Defines a scope for a collection of types, objects, and functions
Program Organization (compiling, linking, make)
History of C++
Further Reading
没有评论:
发表评论