【c++基础】ifstream的构造函数
公共成员函数:
default () ifstream();
initialization ()
explicit ifstream (const char* filename, ios_base::openmode mode = ios_base::in);
explicit ifstream (const string& filename, ios_base::openmode mode = ios_base::in);
copy () ifstream (const ifstream&) = delete;
move () ifstream (ifstream&& x);
mode
| member constant | stands for | access |
|---|---|---|
| in* | input | File open for reading: the internal stream buffer supports input operations. |
| out | output | File open for writing: the internal stream buffer supports output operations. |
| binary | binary | Operations are performed in binary mode rather than text. |
| ate | at end | The output position starts at the end of the file. |
| app | append | All output operations happen at the end of the file, appending to its existing contents. |
| trunc | truncate | Any contents that existed in the file before it is open are discarded. |
code
// ifstream constructor.
#include <iostream> // std::cout
#include <fstream> // std::ifstream int main ()
{
std::ifstream ifs ("test.txt", std::ifstream::in);
char c = ifs.get();
while (ifs.good())
{
std::cout << c;
c = ifs.get();
}
ifs.close();
return ;
}
参考
完
【c++基础】ifstream的构造函数的更多相关文章
- Swift语法基础入门四(构造函数, 懒加载)
Swift语法基础入门四(构造函数, 懒加载) 存储属性 具备存储功能, 和OC中普通属性一样 // Swfit要求我们在创建对象时必须给所有的属性初始化 // 如果没办法保证在构造方法中初始化属性, ...
- c#面向对象基础 静态成员、构造函数、命名空间与类库
静态成员 属性.方法和字段等成员是对象实例所特有的,即改变一个对象实例的这些成员不影响其他的实例中的这些成员.除此之外,还有一种静态成员(也称为共享成员),例如静态方法.静态属性或静态字段.静态成员可 ...
- C++学习基础十——子类构造函数与析构函数的执行
1.子类构造函数的执行: 先执行父类的构造函数,再执行成员对象的构造函数,最后执行自身的构造函数. 当继承多个类时,构造函数的 执行顺序与继承时的顺序 相同,而与子类构造函数调用父类构造函数的顺序无关 ...
- C++学习基础六——复制构造函数和赋值操作符
1.什么是复制构造函数 复制构造函数:是构造函数,其只有一个参数,参数类型是所属类的类型,且参数是一个const引用. 作用:将本类的成员变量赋值为引用形参的成员变量. 2.什么是赋值操作符 赋值操作 ...
- C#基础篇八构造函数和面向对象思想
3.关于 对象创建的几个关键词 Dog d1 = new Dog(); Dog d1 叫做 声明变量 new Dog() 叫做 实例化(创建)对象 4.关于对象.方法和 this 的关系 Dog d1 ...
- Spring基础(5): 构造函数注入无法处理循环依赖
public class Person{ public Leader leader; public Person(Leader l){ this.leader= l; } } public class ...
- C++语言基础(23)-拷贝构造函数
当以拷贝的方式初始化一个对象时,会调用一个特殊的构造函数,就是拷贝构造函数(Copy Constructor). 例如: #include <iostream> #include < ...
- C++语言基础(22)-转换构造函数和类型转换函数
一.转换构造函数 将其它类型转换为当前类类型需要借助转换构造函数(Conversion constructor).转换构造函数也是一种构造函数,它遵循构造函数的一般规则.转换构造函数只有一个参数. # ...
- js基础——面向对象(构造函数)
1.面向对象:类的标志,通过类可创建多个具有相同属性和方法的对象 2.创建对象 1)工厂模式方式:避免重复实例化但未能解决识别问题 function boss(name, age) { ...
随机推荐
- windows 网页打不开github网站
gitbub是外网,经常会遇到访问不了的问题,并且有时能访问也网速好慢. 解决这个问题的方法是 更改hosts文件,地址:C:\Windows\System32\Drivers\etc 我在hosts ...
- C#异常信息获取
try { ; / i; } catch (Exception ex) { /** * 1.异常消息 * 2.异常模块名称 * 3.异常方法名称 * 4.异常行号 */ String str = &q ...
- Windows中查找命令的路径 (类似Linux中的which命令)
where is a direct equivalent: C:\Users\Joey>where cmdC:\Windows\System32\cmd.exeNote that in Powe ...
- Anton and School - 2 CodeForces - 785D (组合计数,括号匹配)
大意: 给定括号字符串, 求多少个子序列是RSGS. RSGS定义如下: It is not empty (that is n ≠ 0). The length of the sequence is ...
- vue 右键菜单插件 简单、可扩展、样式自定义的右键菜单
今天分享的不是技术,今天给大家分享个插件,针对现有的vue右键菜单插件,大多数都是需要使用插件本身自定义的标签,很多地方不方便,可扩展性也很低,所以我决定写了一款自定义指令调用右键菜单(vuerigh ...
- OAF开发中一些LOV相关技巧 (转)
原文地址:OAF开发中一些LOV相关技巧 在OAF开发中,LOV的使用频率是很高的,它由两部分构成一是页面上的LOV输入框(如OAMESSageLovInputBean),二是弹出的LOV模式窗口(O ...
- HDU 1936 区间贪心
/* *区间贪心.前几天刚做了POJ 1328 ...思路完全相同... *最多有100个表情,100行文字.遍历寻找每个表情的所在区间.时间复杂度大约在10^5 ~ 10^6 可以接受. *然后对每 ...
- learning docker steps(7) ----- docker registry 搭建
参考: https://docs.docker.com/engine/reference/builder/ https://hub.docker.com/_/registry/ https://www ...
- mongodb的capped Collection集合
db.createCollection(name, {capped: true, autoIndexId: true, size: 1000, max :100} ) name:集合的名字 cappe ...
- sgu 122. The book 满足ore性质的汉密尔顿回路 难度:2
122. The book time limit per test: 0.25 sec. memory limit per test: 4096 KB There is a group of N (2 ...