ordered pairs, triples, etc

How can I declare an ordered triple (or pair, or 4-tuple, etc.)? For now, all I need to do is to take user input for six numbers, display them as (x,y,z) (a,b,c) and then check to see if (x,y,z) == (a,b,c).

[code/c++]
#include <iostream>

using namespace std;

main()
{
int x, y, z;
int a, b, c;

cout << "List six numbers: " << endl;
cin >> x >> y >> z >> a >> b >> c;

cout << "Ordered triple #1: " /* code here to display (x,y,z) as an ordered triple */ << endl;
cout << "Ordered triple #2: " /* code here to display (a,b,c) as an ordered triple */ << endl;

//if((x,y,z) == (a,b,c))
//cout << "These ordered triples are the same." << endl;

return(0);
}
[/code]


I'm told that I need to use #include <utility> for ordered pairs, and I assume this is the case for triples, 4-tuples, 5-tuples, etc. Yes?

Can anyone help? Thanks!
Zachary
The C++ Standard Template Library uses pairs of things internally and their pair thing is available for us to use. But I think you want something a bit different.

You probably want your own class that has some container that stores values in order. That way you can have a variable number of items.

Also, if you define operator<<, you could pass it to cout just like you do for int in your example.
boost::tuple for a general n-tuple (it might be limited to 9)

1
2
boost::tuple<int,char,string> tup( 4, 'c', string( "Hello World" ) );
cout << "The string is " << tup.get<2>() << endl;


www.boost.org for documentation.
Topic archived. No new replies allowed.