#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

class Cords
{
public:
int x,y,z;
};

class Object:public Cords
{
int a,b,c;
public:
vector<Cords> vCords;
void insertCords();
void getCords();
};

void Object::insertCords()
{
Cords theCords;
int x=1;
do
{
cout<<"Enter X:"<<endl;
cin>>x;
cout<<"Enter a b c:"<<endl;
cin>>a>>b>>c;
theCords.x=a;
theCords.y=b;
theCords.z=c;
vCords.push_back(theCords);
}while(x!=0);
}

void Object::getCords()
{
cout<<"ORIGINAL VALUES BEFORE SORTING:"<<endl;
for(int i=0;i<vCords.size();i++)
cout<<vCords[i].x<<" "<<vCords[i].y<<" "<<vCords[i].z<<endl;
**sort(vCords.begin(),vCords.end());**
}

int main()
{
Object obj;
obj.insertCords();
obj.getCords();
return 0;
}

HOw to use sort function for vector vCords. It din't work with algorithm sort(). Is there other possibility of sorting these types of vectors

By default std::sort() uses operator< to handle the relation between items. Since you have neither an overloaded operator< nor specify a custom comparison function, of course it doesn't work.

Consider using the three argument version of std::sort(). You can find details and examples here.

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.