I'll have to try to learn the search, I don't think I've tried that before.
I did find some stuff on c.l.c++ to help me fix my output a little.
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <iterator>
template< typename T >
std::ostream& operator<<(std::ostream& os, std::vector<std::vector<T> >& array)
{
typedef typename std::vector<std::vector<T> >::const_iterator ci;
for ( ci it = array.begin(); it != array.end(); ++it )
{
std::copy((*it).begin(), (*it).end(), std::ostream_iterator<T>(os, ", "));
os << '\n';
}
return os;
}
int main()
{
std::ifstream file("file.txt");
if ( file )
{
std::vector<std::vector<int> > array;
//
// Input
//
std::string line;
while ( std::getline(file, line) )
{
std::vector<int> row;
char ch;
std::istringstream ss(line);
while ( ss >> ch )
{
row.push_back(ch - '0');
}
array.push_back(row);
}
//
// Output
//
std::cout << array << std::endl;
}
return 0;
}
/* my output
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 0, 0, 1, 0, 0, 0, 1,
0, 1, 0, 0, 1, 0, 0, 1, 1,
0, 0, 1, 0, 0, 1, 0, 0, 1,
*/
[edit]I'll start here .