C++IO Stream的学习笔记

Posted songyuc

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C++IO Stream的学习笔记相关的知识,希望对你有一定的参考价值。

1 路径操作:fs::path

OperationSymbolExample
Concatenation/path_a / path_b

2 文件读取

ifstream fin;
fin.open(file_path, ios::in);
if (!fin.is_open()) 
    cout << "Not found file!" << endl;
    return EXIT_FAILURE;

3 控制台输入数据

使用cin在控制台输入数据并判断是否读取成功:

int x;
if (std::cin>>x) 
    // Input: 10
    // cin流读取成功:bool(cin) = true, eofbit = false
    // Input: ... (unexpected input)
    // cin流读取失败:bool(cin) = false, eofbit = false
    std::cout<<"true"<<(std::cin.eof());

以上是关于C++IO Stream的学习笔记的主要内容,如果未能解决你的问题,请参考以下文章