📜  c++ 打开文件 - C++ 代码示例

📅  最后修改于: 2022-03-11 14:44:48.102000             🧑  作者: Mango

代码示例3
// Reading a file

#include 
#include 
#include 

int main() 
{
    std::string line;

    std::ifstream file("example.txt");
    if(file.is_open())
    {
        while(getline(file, line))
        {
            std::cout << line << '\n';
        }
        file.close();
    }
    else std::cout << "Unable to open file";

    return 0;
}