who'd like to explain the usuage of vecor<pair< , > > ?

H

hardi.pertel

It is best to show me some examples.

Thanks a lot.

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

vector<pair<int, int> > squares;

int main()
{
for (int i = 0;i < 5;++i)
{
squares.push_back(make_pair(i, i*i));
}

for (vector<pair<int, int> >::const_iterator pos =
squares.begin();pos != squares.end();++pos)
{
cout << pos->first << "^2 = " << pos->second << endl;
}
}
 
A

asdf

Thanks.

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

vector<pair<int, int> > squares;

int main()
{
for (int i = 0;i < 5;++i)
{
squares.push_back(make_pair(i, i*i));
}

for (vector<pair<int, int> >::const_iterator pos =
squares.begin();pos != squares.end();++pos)
{
cout << pos->first << "^2 = " << pos->second << endl;
}
}
 
B

BobR

asdf wrote in message...
It is best to show me some examples.
Thanks a lot.

NOooo problem.

// -------
#include <iostream>
#include <ostream>

int main(){
std::cout << "Hello World" << std::endl;
return 0;
} // main()
// -------

Another example:

// -------
#include <iostream>
#include <ostream>

class Hi{ public:
void Say( std::eek:stream &out ){
out << "Hello World" << std::endl;
return;
}
};

int main(){
Hi Ima;
Ima.Say( std::cout );
return 0;
} // main()
// -------

Your turn.
 
A

asdf

Thanks.

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

vector<pair<int, int> > squares;

int main()
{
for (int i = 0;i < 5;++i)
{
squares.push_back(make_pair(i, i*i));
}

for (vector<pair<int, int> >::const_iterator pos =
squares.begin();pos != squares.end();++pos)
{
cout << pos->first << "^2 = " << pos->second << endl;
}
}
 
H

hardi.pertel

BobR said:
asdf wrote in message...

NOooo problem.

// -------
#include <iostream>
#include <ostream>

int main(){
std::cout << "Hello World" << std::endl;
return 0;
} // main()
// -------

Another example:

// -------
#include <iostream>
#include <ostream>

class Hi{ public:
void Say( std::eek:stream &out ){
out << "Hello World" << std::endl;
return;
}
};

int main(){
Hi Ima;
Ima.Say( std::cout );
return 0;
} // main()
// -------

Your turn.

If that's vector<pair< , > > then I must be really blind as I can't see
it.
 
B

BobR

(e-mail address removed) wrote in message ...
If that's vector<pair< , > > then I must be really blind as I can't see
it.

In the message body (s)he said, "It is best to show me some examples.". So, I
showed some examples! I saw NO question about anything IN the post!

template <class A, class B> class pair{ public:
A a;
B b;
};

For vector you do.... Oh wait, did you actually mean 'std::vector'? You
should state that!

< you starting to get-it? >
<http://www.parashift.com/c++-faq-lite/how-to-post.html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top