Created
July 29, 2012 17:05
-
-
Save PeterHajdu/3200266 to your computer and use it in GitHub Desktop.
Reading character matrix from file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cassert> | |
#include <iostream> | |
#include <fstream> | |
#include <vector> | |
#include <iterator> | |
std::vector< std::string > | |
getContainerFromFile( const std::string& fileName ) | |
{ | |
std::vector< std::string > ret; | |
std::ifstream matrixFile( fileName.c_str() ); | |
std::string line; | |
while ( std::getline( matrixFile, line ) ) | |
{ | |
ret.push_back( line ); | |
} | |
return ret; | |
} | |
int main( int argc, char* argv[] ) | |
{ | |
assert( argc > 1 && "No filename argument passed." ); | |
std::vector< std::string > matrix( getContainerFromFile( argv[ 1 ] ) ); | |
std::copy( matrix.begin(), matrix.end(), std::ostream_iterator< std::string >( std::cout, "\n" ) ); | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.......... | |
...X...... | |
...X...... | |
...X...... | |
.......... | |
.......... | |
.......... | |
.......... | |
....XXX... | |
.......... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment