Answers for "g++ -o file file.cpp"

C++
0

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 << '\n';
        }
        file.close();
    }
    else std::cout << "Unable to open file";

    return 0;
}
Posted by: Guest on December-21-2021
0

files c++

fstream  afile;
afile.open("file.dat", ios::out | ios::in );
Posted by: Guest on September-22-2021

Browse Popular Code Answers by Language