`
zhang19581987
  • 浏览: 60242 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
社区版块
存档分类
最新评论

C++学习笔记——3

    博客分类:
  • C++
阅读更多
typedef double wages;

enum open_modes {input, output, apped};

枚举成员的值可以是不唯一的,枚举类型的对象的初始化或赋值,只能通过其枚举成员或同一枚举类型的其它对象来进行。

当进行string对象和字符串字面值混合连接操作时,+操作符的左右操作数必须至少有一个是string类型的:
string s1 = "hello";
string s2 = "world";
string s3 = s1 + ", ";     // OK
string s4 = "hello" + ", " // error: no string operand
string s5 = s1 + ", " + "world"; // OK; each + has string operand
string s6 = "hello" + ", " + s2;  // error; can't add string literals

vector 对象的size
vector成员函数size返回相应vector类定义的size_type的值,
使用size_type类型时,必须指出该类型是在哪里定义的,vector类型总是包括vector的元素类型:
vector<int>::size_type     // OK
vector::size_type          // error

vector的下标只能用于获取已存在的元素,不能用来添加元素.

vector<string>::const_iterator  const_iterator类型只能用于读取容器内元素的值,不能改变其值。


不允许数组直接复制和赋值。
如:
int ia[] = {0, 1, 2}; // OK: array of ints
int ia2[]{ia);         // error: cannot initialize one array with another
int ia3[3];
ia3 = ia;          // eroor : cannot assign one array to another.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics