求助关于二维向量读取文件???
我最近有个不规则文件:大致如下1 23 45 6
12 4 5 6 7 8 9
12 5 6 8
3 4 5 6
我想把它存入二维向量里并且打印出来,可是我写的程序编译时也没显示什么错误,就是什么也打印不出来
请各位高手能否指点一下呢
# include <iostream>
# include <fstream>
# include <vector>
# include <string>
# include <cassert>
using namespace std;
typedef vector<int> onevector;
typedef vector<onevector> twovector;
void fill(const string&filename,twovector&thevector);
void print ( ostream&out,const twovector & avector);
int main()
{
cout << "please input the name of the file:"<< endl;
string file;
cin >> file;
twovecctor avec;
fill2(file,avec);
cout << "how to do?\n";
// cout << avec[0][2] <<'\t' << endl;
print (cout,avec);
}
void fill (const string& filename,twovector & avector)
{
ifstream instream(filename.data());
assert (instream.is_open());
twovector locvector;
int avalue;
char separate;
for (;;)
{
onevector arow;
for (;;)
{
separate = instream.peek();
// if (separate == '\n') break;
instream >> avalue;
if (instream.eof()) return;
arow.push_back(avalue);
}
instream.get (separate);
locvec.push_back(arow);
}
avector = locvec;
instream.close();
}
void print (ostream&out,const twovector & avector)
{
for ( int i =0; i < avector.size(); i++)
{
for (int j=0; j < avector[i].size(); j++)
out << avector[i][j] << "\t";
out << endl;
}
}