Skip to content

Instantly share code, notes, and snippets.

@PeterHajdu
Created July 29, 2012 17:05
Show Gist options
  • Save PeterHajdu/3200266 to your computer and use it in GitHub Desktop.
Save PeterHajdu/3200266 to your computer and use it in GitHub Desktop.
Reading character matrix from file
#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;
}
..........
...X......
...X......
...X......
..........
..........
..........
..........
....XXX...
..........
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment