txt中读出非数字的行列号程序如下
当读到非数字时显示其行列号,改了好久都是错的,大家帮我看看吧#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include<ctype.h>
#include <stdlib.h>
using namespace std;
inline void makeitem(vector<int>& item,istringstream &in );
int main()
{
string line;
ifstream f("D:\\VS2012\\CPP\\txt1\\abc.txt");
if(!f.is_open())
{
cout<<"error openfile"<<endl;return 1;
}
vector<int> item;
vector<vector<int> > arr;
int num=0;
while(!f.eof())
{
int num=0;
getline(f,line);
if(line.empty())continue;
istringstream input(line);
item.clear();
while(!input.eof())
{
input>>num;
item.push_back(num);
}
arr.push_back(item);
}
f.close();
//output arr
for (int i=0;i<arr.size();i++)
{
item=arr[i];
for (int j=0;j<item.size();j++)
{
cout<<item[j]<<" ";
}
cout<<endl;
}
int max[]={0};
for(int i=0;i<arr.size();i++)
{
for(int j=0;j<item.size();j++)
{
if(arr[i][j]>max[i])
{
max[i]=arr[i][j];
}
}
cout<<max[i]<<" ";
cout<<endl;
}
getchar();
}