随笔分类 - C/C++
摘要:#include<iostream>#include<string>#include<algorithm>using namespace std;class MyClass{public: static int num; int data; void DisplayData() { cout<<"Initializion"<<data<<"\n"; } MyClass() { cout<<"MyClass Create\n"; num++; } MyC
阅读全文
摘要:#include<iostream>#include<string>using namespace std;class Sales_item;//前置申明,让Test识别Sales_itemclass Test{public: void GetName(Sales_item &item); std::string TestName;};class Sales_item{ friend void Test::GetName(Sales_item &item); //freind class Test;的话Test任何方法都能访问public: Sales_
阅读全文
摘要:#include<iostream>#include<vector>#include<string>#include<numeric>#include<algorithm>#include<iterator>using namespace std;bool isDivided2(int num){ return num%2==0;}int main(int cnt,char *argv[]){ int l[5]={1,3,3,4,6}; int findl[1]={10}; cout<<accumulate(l
阅读全文
摘要:<stdexcept> 头文件exception 最常见的问题。 以下异常都是exception的子类runtime_error 运行时错误:仅在运行时才能检测到问题 range_error 运行时错误:生成的结果超出了有意义的值域范围 overflow_error 运行时错误:计算上溢 underflow_error 运行时错误:计算下溢 logic_error 逻辑错误:可在运行前检测到问题 domain_error 逻辑错误:参数的结果值不存在 invalid_argument 逻辑错误:不合适的参数 length_error 逻辑错误:试图生成一个超出该类型最大长度的...
阅读全文
摘要:常用调试常量__FILE__ 文件名 __LINE__ 当前行号 __TIME__ 文件被编译的时间 __DATE__ 文件被编译的日期 cerr <<"File:"<< __FILE__ <<endl <<"Line:"<< __LINE__ <<endl <<"Date:"<< __DATE__ <<endl <<"Time:"<< __TIME__ <<endl;ND
阅读全文
摘要:类型转换:因为要覆盖通常的标准转换,所以需显式使用强制类型转换。显式使用强制类型转换的另一个原因是:可能存在多种转换时,需要选择一种特定的类型转换。我们将在第 14 章中详细讨论这种情况。 命名的强制类型转换符号的一般形式如下: cast-name<type>(expression); 其中 cast-name 为 static_cast、dynamic_cast、const_cast 和reinterpret_castint rst=10;double b=10.23; rst*=static_cast<int>(b);//为了防止把rst转换为double这个不必要
阅读全文
摘要:字面值:u 定义为unsignedl 定义为long例:-12u 12l -12ul科学计数:ExF 或者ExLF x代表10的次方数3.14E5F //314000转义:\num num可以是八进制\062,十六进制\xddd字符串:L代表宽字符 L'a' L"a"多行字面值 \ 定义引用:把a的引用给bint a=10;int &b=a;b++;//a,b都为11和以下等价int *b=&a;(*b)++;迭代器:vector<int> v;for(vector<int>::iterator itr=v.begin
阅读全文
浙公网安备 33010602011771号