c++
xicq
这个作者很懒,什么都没留下…
展开
-
string
字符数组转化成string类型 char ch [] = "ABCDEFG"; string str(ch);//也可string str = ch; 或者 char ch [] = "ABCDEFG"; string str; str = ch;//在原有基础上添加可以用str += ch; 将string类型转换为字符数组 char buf[10]; string str原创 2014-04-21 20:38:48 · 489 阅读 · 0 评论 -
C++ Primer 学习4:string类使用重载操作符+的注意
//string类重载操作符+ 注意:对于string类初始化使用到重载操作符+必须重载操作符+左右至少有一个sting类对象 #include #include using namespace std; int main() { string s1 = "12"; string s2 = s1 + "34"; string s3 = s1 + s2; //原创 2015-06-25 19:05:04 · 579 阅读 · 0 评论 -
C++ Primer学习7:const iterator与const_iterator的区别
const iterator是指iterator是参量,不可修改 const_iterator是iterator指向的元素不可修改 #include #include using namespace std; int main() { vector num(10,9); //对比下面2个迭代器 const vector::iterator iter1 = num原创 2015-06-25 19:37:16 · 519 阅读 · 0 评论 -
C++ Primer学习5:vector使用下标操作元素注意
vector使用下标注意:vector[i]使用时,只有该i位元素存在时,才能使用 #include #include using namespace std; int main() { vector str; vector str1; for(vector::size_type i = 0; i != 5; ++i) { str.pus原创 2015-06-25 19:10:52 · 671 阅读 · 0 评论 -
C++ Primer学习6:const指针 和 指针与const限定符区别
指针与const限定符 c++强制要求const对象的指针必须是const特性 例如const int *p; p不是const,可以不初始化 这里限定了p指针所指向的对象类型是const (p可以被修改,但是p指向的const对象不能被修改) const指针 例如 int a = 3; int *const p = &a; 指向某对象的const指针,指针不能被修改,必须初始化。原创 2015-06-25 19:16:34 · 414 阅读 · 0 评论 -
C++ primer学习1:细节:标准化后C++中,定义在for循环内部的变量,循环外部不可使用
标准化后C++中,定义在for循环内部的变量,循环外部不可使用 #include using namespace std; int main() { int sum = 0; for(int i = 0; i < 5; ++i) { sum += i; } i = 3; //报错,由于在标准化后C++中,定义在for语句头的原创 2015-06-11 11:50:43 · 1252 阅读 · 0 评论 -
C++ Primer学习2:细节:引用
引用是对象或变量的的别名,对引用变量的操作相当于对被引用变量的操作。 定义:类型 & 变量名 初始化:引用类型变量必须初始化; 初始化关联到其他类型的变量#include using namespace std; int main() { int ival = 10; int &refVal = ival; int &refVal2; //error: ‘原创 2015-06-12 21:27:38 · 459 阅读 · 0 评论 -
C++ Primer学习3:枚举类型
枚举定义: enum 变量名 { }; enum Color { red, yellow, black, white }; 枚举类型内元素第一元素如果没有初始化赋值的话,默认为0,后面元素比前面元素大1(元素未赋值); 枚举成员是常量,整数。 枚举类型变量只能该枚举内的元素赋值,但不能以其代表的整型数赋值(除非强制转化) 枚举类型变量可进行算术运算或与其他整型变量进行运算,自原创 2015-06-12 23:33:02 · 400 阅读 · 0 评论