64,683
社区成员
发帖
与我相关
我的任务
分享
const int max = 100
string words[max];
RtlZeroMemory(words,sizeof(words));
string zs[max];
RtlZeroMemory(words,sizeof(zs));
int a =50; //假设文本每行50个字符,两个内容用空格分开
ifstream fin ("date.txt");
if (!fin.bad())
{
for(int n = 0; n<50; n++)
{
fin.ignore( a , '^'); //我是要忽略已经读过的和没用的~
fin>>words[n]>>zs[n];
a+=100;
}
fin.close();
}
//我的txt是这生成的
ofstream fout ("date2.txt");
if (!fin.bad())
{
fout<<""<<endl
<<setw(20)<<words[0]<<setw(30)<<zs[0]<<endl;
fout.close();
}
istringstream istr;
string first,second;
for(int i=0;i<n;i++)
{
fin.getline(words,20);//这里是读取一行的前20个字符。放入words中
istr(words);
istr>>first; //取到的是你文件中的一行的第一个字符串,放入first中
istr>>second;//取到第二个字符串,放入second中
}