Hi everyone,
I'm trying sort a C++ struct and print the result as output file.
I don't know how to sort the structure. Did anyone develop this before?
Thanks a lot,
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <ctime>
using namespace std;
#define N_P 6
struct p_t {
int id1;
int id2;
int id3;
string gender;
} indP [N_P];
void printP (p_t p);
int main ()
{
string mystr;
int n;
for (n=0; n<N_P; n++)
{
cout << "Enter id1: ";
getline (cin,mystr);
stringstream(mystr) >> indP[n].id1;
cout << "Enter id2: ";
getline (cin,mystr);
stringstream(mystr) >> indP[n].id2;
cout << "Enter id3: ";
getline (cin,mystr);
stringstream(mystr) >> indP[n].id3;
}
cout << "\nYou have entered these pFile:\n";
for (n=0; n<N_P; n++)
printP(indP[n]);
return 0;
}
void printP (p_t p)
{
cout << "ID1 " << p.id1 << "\n";
cout << "ID2 " << p.id2 << "\n";
cout << "ID3 " << p.id3 << "\n";
}
//