-
C++ Primer 读书笔记 - 第四章
添加时间:2013-5-20 点击量:这一章更多的是在讲C说话的器材。
Pointers to const Objects
const double ptr
const Pointers
double const ptr = &value //必须初始化
const Pointer to a const Object
cosnt double const ptr = &value
Pointers and Typedefs
Typedef string pstring
const pstring cstr;
其实const pstring cstr 等价于 string const cstr
const int pci_ok = new const int[100]() //初始化为0
[] pia //数组删除动态内存
char arr[0] //error: cannot define zero-length array
char cp = new char[0] //ok: but cp cannot be dereferenced
int ip[4] //array of pointers to int
int (ip)[4] //pointer to an array of 4 ints
Library strings and C-style Strings
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
string s(abcdefghi);
const char str = s.c_str(); //The array return by c_str is not guaranteed to be valid indefinitely
s[0] = w;
cout << s << endl;
cout << str << endl;
return 0;
}
所有随风而逝的都属于昨天的,所有历经风雨留下来的才是面向未来的。—— 玛格丽特·米切尔 《飘》