Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ open file

// Reading a file

#include <iostream>
#include <fstream>
#include <string>

int main() 
{
    std::string line;

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

    return 0;
}
 
PREVIOUS NEXT
Tagged: #open #file
ADD COMMENT
Topic
Name
4+2 =