#include<fstream>
#include<string>
#include<iostream>
using namespace std;
int main()
{
string file;
string s;
int linenumber = 1;
int lineaim;
string::size_type rowaim,lrowaim;
string aimarray[2048];
int i = 0;
//选列的初始值
string str1(" ");
string::size_type pos = 0, pre_pos = 0;
cout << "enter the beginning linenumber you want to extract : ";
cin >> lineaim;
//cout << lineaim << endl;
cout << "enter the rownumber you want to extract: ";
cin >> rowaim;
cout << "enter the last rownumber you want to extract: ";
cin >> lrowaim;
//cout << rowaim << endl;
cout << "enter the filename : ";
cin >> file;
ifstream infile(file);
//读列
//读入行
while (getline(infile, s))
{
//选择行
if (linenumber >= lineaim)
{
//选择列
int j = 0;
//标记到第一个空格
while ((pos = s.find_first_of(str1, pos)) != string::npos)
{
/*cout << pos << pre_pos<<endl;*/
if (pos - pre_pos >1) //不显示连续空格
{
if (j == rowaim-1)
{
aimarray[i] = s.substr(pre_pos, pos - pre_pos);
}
j++;
}
// 移到被找到元素的后一位置
pre_pos = ++pos;
}
if (rowaim == lrowaim)
{
aimarray[i] = s.substr(pre_pos, pos - pre_pos);
}
pos = 0;
pre_pos = 0;
cout << aimarray[i] << endl;
i++;
}
linenumber++;
};
system("pause");
return 0;
#include<string>
#include<iostream>
using namespace std;
int main()
{
string file;
string s;
int linenumber = 1;
int lineaim;
string::size_type rowaim,lrowaim;
string aimarray[2048];
int i = 0;
//选列的初始值
string str1(" ");
string::size_type pos = 0, pre_pos = 0;
cout << "enter the beginning linenumber you want to extract : ";
cin >> lineaim;
//cout << lineaim << endl;
cout << "enter the rownumber you want to extract: ";
cin >> rowaim;
cout << "enter the last rownumber you want to extract: ";
cin >> lrowaim;
//cout << rowaim << endl;
cout << "enter the filename : ";
cin >> file;
ifstream infile(file);
//读列
//读入行
while (getline(infile, s))
{
//选择行
if (linenumber >= lineaim)
{
//选择列
int j = 0;
//标记到第一个空格
while ((pos = s.find_first_of(str1, pos)) != string::npos)
{
/*cout << pos << pre_pos<<endl;*/
if (pos - pre_pos >1) //不显示连续空格
{
if (j == rowaim-1)
{
aimarray[i] = s.substr(pre_pos, pos - pre_pos);
}
j++;
}
// 移到被找到元素的后一位置
pre_pos = ++pos;
}
if (rowaim == lrowaim)
{
aimarray[i] = s.substr(pre_pos, pos - pre_pos);
}
pos = 0;
pre_pos = 0;
cout << aimarray[i] << endl;
i++;
}
linenumber++;
};
system("pause");
return 0;
}