error C2039: 'iterator_category' : is not a member of 'std::pair<_Ty1,_Ty2>'It is in my "totalDis(...)" method. When I try to call "distance(...)" with two pairs from my vector, it tells me there are errors in xutility. There are a ton of errors, but the one above encapsulates them all. I am hoping the error is something obvious that I am missing.
Thank you for the help!
#include <fstream>
using std::ifstream;
#include <iostream>
#include <cmath>
#include <string>
using std::string;
#include <utility>
using std::make_pair;
using std::pair;
#include <vector>
using std::vector;
typedef pair< double, double > point;
typedef vector< point > graph;
typedef unsigned long ulong;
//----------------------------------------------------------
// pre: ifstream is a file containing the number of
// coordinates to read in and the number of coordinates
// pst: returns vector of coordinate pairs
graph readFile( ifstream & );
// pre: graph is a vector of coordinate pairs
// pst: returns a vector of coordinate pairs, representing
// the TSP path that visits each node exactly once
graph slowTSP( const graph & );
// pre: graph is a vector of coordinate pairs
// pst: returns a vector of coordinate pairs, representing
// the TSP path that visits each node exactly once
graph fastTSP( const graph & );
// pst: returns the linear distance between two
// coordinate points
const double distance( const point, const point );
// pst: returns the total linear distance of the cycle
// that visits each point exactly once
const double totalDis( const graph & );
//----------------------------------------------------------
const string FILENAME( "input.txt" );
int main( int num, char **args )
{
ifstream fin( FILENAME.c_str() );
graph vec = readFile( fin );
// print coordinates
for (int i=0; i<vec.size(); ++i)
std::cout << "(" << vec[i].first << ", "
<< vec[i].second << ")\n";
return 0;
}
//----------------------------------------------------------
graph readFile( ifstream & fin )
{
graph v;
ulong size;
fin >> size; // get number of coordinates
double x;
double y;
for (int i=0; i<size; ++i) {
// construct list of coordinate pairs
fin >> x >> y;
v.push_back( make_pair(x, y) );
}
return v;
}
//----------------------------------------------------------
graph slowTSP( const graph & in )
{
graph min( in );
return min;
}
//----------------------------------------------------------
graph fastTSP( const graph & in )
{
graph v( in );
return v;
}
//----------------------------------------------------------
const double distance( const point a, const point b )
{
// a^2 + b^2 = c^2
return (sqrt( pow((a.first - b.first), 2) +
pow((a.second - b.second), 2)));
}
//----------------------------------------------------------
const double totalDis( const graph & in )
{
double dis = 0;
// distance from start to end point
for ( int i=0; i<in.size(); ++i) {
double temp = distance(in.at(i-1), in.at(i));
dis += temp;
}
// distance from end point back to start
dis += distance( in.at(in.size()-1), in.at(0) );
return dis;
}
//----------------------------------------------------------


Sign In
Create Account


Back to top









