Skip to main content
Advanced Search
Search Terms
Content Type

Exact Matches
Tag Searches
Date Options
Updated after
Updated before
Created after
Created before

Search Results

5 total results found

String 包含 前缀包含

Java 字符串

包含 语法 public boolean contains(CharSequence chars) 示例 String myStr = "abc"; System.out.println(myStr.contains("a")); //返回True System.out.println(myStr.contains("b")); //返回True System.out.println(myStr.contains("d")); //返回False 前缀包含 语法 public boolean startsWit...

文件IO 文件读写

C++ C++ IO流 I/O 文件读写

头文件已包含在iostream 打开文件 fstream fp; //实例化文件操作对象 fp.open("fileName",openmode); //以openmode方式打开fileNmae文件 ifstream和ofstram特用于输入/输出 ifstream in; //读取流对象实例化 in.open("fileName"); //打开要读取的文件,打开方式默认为ios::in in.open("fileName",openmode); //重载,以自定义打开方式打开文件 ...

重载<<运算符

C++ 运算符重载

<<运算符是双目运算符,其左右分别为它的两个参数 一般情况下,<<左边为流的下一个目的地,右边为流入的内容 下例中通过重载<<来输出分数类(Rational)中的内容。(成员a:分子;成员b:分母) class Rational{ private: int a; int b; //声明友元函数以访问私有成员 friend std::ostream& operator<<(std::ostream& os , Rational r); Rational(int a,int b); //实...

副本构造器(重载=,赋值运算符)

C++ class 类

当一个类中包含指针成员,强烈建议使用副本构造器(重载=),以免发生越界或内存泄漏 例如: /*假设有class Test,内有一个int* ptr*/ class Test a; a.ptr=new int(3); b=a; //此时b中的ptr也指向a中ptr的地址 delete a.ptr; cout<<*b.ptr; //报错,越界访问 副本构造器: class Test{ public: int* ptr; ~Test(){ delete th...

vector

C++ STL

为了方便,本页面所有演示类型均为int 构造函数 vector<int> v1; //创建一个空容器 vector<int> v2(n); //创建一个长度为n的容器,所有元素默认为0 vector<int> v3(n,elem); //创建一个长度为n的容器,所有元素默认为elem vector<int> v4(start,end); //(start和end为int*)创建一个容器,将start到end之间的内存复制给容器(左闭...