C++/ 一,导出文本中的数据

#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;

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值