The question was if there was something other than fstream I could use to read a file. I didn't learn that I could use standard in on a file until after I had asked the question. I brought it up to make sure the information was correct.
#include <iostream>
#include <string>
#include <iomanip>
int main()
{
int line_number = 0 ;
std::string line ;
while( std::getline( std::cin, line ) ) // for each line read from stdin
std::cout << std::setw(4) << ++line_number << ". |" << line << '\n' ;
}
echo && g++ -std=c++17 -O3 -march=native -Wall -Wextra -pedantic-errors main.cpp
./a.out < main.cpp #standard input is redirected; it now comes from the file main.cpp
echo && echo ============ && echo
clang++ -std=c++17 -stdlib=libc++ -O3 -march=native -Wall -Wextra -pedantic-errors main.cpp -lsupc++
./a.out < main.cpp #standard input is redirected; it now comes from the file main.cpp