#include <iostream>
#include <fstream>
#include <string>
int main()
{
// open the file for input
std::ifstream fin( "CPSC121data.txt" ) ;
if( !fin.is_open() )
{
std::cout << "failed to open file for input\n" ;
return 1 ;
}
std::string line ;
// http://www.cplusplus.com/reference/string/string/getline/while( std::getline( fin, line ) ) // for each line read from the file
{
// print the line
std::cout << line << '\n' ;
}
}
#include <iostream>
#include <fstream>
#include <string>
int main()
{
// if the file is successfully opened for input
if( std::ifstream fin{ "CPSC121data.txt" } ) // note: initialiser is within braces
{
std::string line ;
// http://www.cplusplus.com/reference/string/string/getline/while( std::getline( fin, line ) ) // for each line read from the file
{
// print the line
std::cout << line << '\n' ;
}
}
else // attempt to open the file failed
{
std::cout << "failed to open file for input\n" ;
return 1 ;
}
}