can not print a <pair>

A

arnuld

C++ Primer 4/e says, every pair has 2 members named <first> and <last> but
g++ refuses to accept so. I have just created a pir and trying to print
its both members:


#include<iostream>
#include<string>
#include<utility>


int main()
{
std::pair<std::string, int> my_pair;
std::cin >> my_pair.first >> my_pair.last;

std::cout << my_pair.first << "\n"
<< my_pair.last << "\n";

return 0;
}


========= OUTPUT ==============

/home/arnuld/programs $ g++ -ansi -pedantic -Wall -Wextra test.cpp
test.cpp: In function ‘int main()’:
test.cpp:12: error: ‘struct std::pair<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, int>’
has no member named ‘last’
test.cpp:15: error: ‘struct std::pair<std::basic_string<char,
std::char_traits<char>,std::allocator<char> >, int>’ has no member named
‘last’ /home/arnuld/programs $
 
A

arnuld

C++ Primer 4/e says, every pair has 2 members named <first> and <last> but
g++ refuses to accept so. I have just created a pir and trying to print
its both members:


... [SNIP]......


I am so SORRY, I messed up the variables and mebers names in example in
section 10.1 of C++ Primer 4/e. g++ is right :), There is no memeber
named last, there are 2 members, <first> and <second> .

I apologize for messing up.
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top