简体   繁体   中英

How to read from a file using fstream

void Tutorial() {
    fstream myFile;
    myFile.open("Tutorial.txt", ios::in);
    if (myFile.is_open()) {
        string line;
        while (getline(myFile, line))
        {
            std::cout << line << endl;
        }
        myFile.close();
    }
}

I have a file inside the folder called tutorial.txt , but it does not print out the characters in the console when the function is called.

Set the working directory here (right click, properties on the project)

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM