#include<fstream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{ clrscr();
ofstream fout("a");
fout<<5<<"\n"<<3<<"\n"<<2<<"\n"<<4<<"\n"<<1;

fout.close();
ifstream fin("a");

int i,j,k,l=0,m,n,o;
while(fin)
{
fin>>i;
l++;
}
l--;
fin.close();
fstream fin1("a",ios::ate,ios::in);
fin1.seekg(0);
for(i=0;i<l-1;i++)
{ for(j=0;j<l-i-1;j++)
{ o=fin.tellg();
fin1>>m;
fin1>>n;
if(m>n)
{ fin1.seekg(o);
fin1<<n;
fin1<<m;
fin1.seekg(o+1);
}
}
}


}


//file sorting is not working if anyone can help..

Recommended Answers

All 3 Replies

Why am I not surprised it doesn't work? All it does is read the data and then does nothing with it.

lines 30 and 31: fin1 is an input stream, not output.

sir ancient dragon,
line 21 declares fin1 as input as well as output stream.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.