利用vector对文件的内容进行按行存储并输出
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
int main(void)
{
ifstream fp("I:\\temp.txt");
vector< vector<double> > tmp;
// string str;
char str[100];
double i;
char *ch,*ch1;
int num;
while(!fp.eof())
{
vector<double> m1;
// getline(fp,str,'\n');
fp.getline(str,100);
num = fp.gcount();
cout<<"num = "<<num<<endl;
// ch1 = const_cast<char *>(str.c_str());
ch1 = const_cast<char *>(str);
ch = strtok(ch1," ");
m1.push_back(atof(ch));
vector<double>::iterator c22 = m1.begin();
while(ch)
{
ch = strtok(NULL," ");
m1.push_back(atof(ch));
}
m1.pop_back();
tmp.push_back(m1);
}
vector< vector<double> >::iterator cnt = tmp.begin();
vector<double> v1 = *(cnt);
while(cnt != tmp.end())
{
vector<double>::iterator cnt1 = v1.begin();
while(cnt1 != v1.end())
{
cout<<*cnt1<<" ";
cnt1++;
}
cnt++;
cout<<endl;
v1 = *cnt;
}
return 0;
}