Read a file line by line: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary |
||
Line 269: | Line 269: | ||
return 0; |
return 0; |
||
}</lang> |
|||
=={{header|C++}}== |
|||
<lang C++>#include <fstream> |
|||
#include <string> |
|||
#include <iostream> |
|||
int main( int argc , char** argv ) { |
|||
int linecount = 0 ; |
|||
std::string line ; |
|||
std::ifstream infile( argv[ 1 ] ) ; |
|||
if ( infile ) { |
|||
while ( getline( infile , line ) ) { |
|||
std::cout << linecount << ": " << line << '\n' ;//supposing '\n' to be line end |
|||
linecount++ ; |
|||
} |
|||
} |
|||
infile.close( ) ; |
|||
return 0 ; |
|||
}</lang> |
}</lang> |
||