Vector String Output

I need help understanding vectors. I have a huge problem understanding the concept. I need help on how to output a selected amendment when the user inputs the number they want to know. I know how to make the vector. If anyone can tell me in lamest terms, that would be great because I really want to pursue my future in Computer Science.
Thank you.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 #include "std_lib_facilities_4.h"


const int amend_count = 27;

int main ()
{
        vector<string>amend_count {
                "Amendment 1 gurantees freedom of speech, religion, press, assembly, and petition.",
                "Amendment 2 gives the right to bear arms.",    
                "Amendment 3 states no forced quatering of soldiers in private homes.", 
                "Amendment 4 gives citizens protection from illegal searches & seizures.",      
                "Amendment 5 is the right to a fair trial.",    
                "Amendment 6 elaborates on criminal procedures, speedy trials, confront witnesses, and have an attorney.",      
                "Amendment 7 is trial by jury in civil cases.", 
                "Amendment 8 protects citizens from cruel and unusual punishments.",    
                "Amendment 9 retains the rights by the people.",
                "Amendment 10 states powers not delegated to the fed gov't are reserved to the states and people.",     
                "Amendment 11 limits the jurisdiction of federal courts.",      
                "Amendment 12 changes in manner of electing presidents and vice presidents.",   
                "Amendment 13 abolishes slavery.",      
                "Amendment 14 details Equal Protection Clause.",
                "Amendment 15 allows those free from slavery to vote.", 
                "Amendment 16 gives Congress power to collect taxes on income.",
                "Amendment 17 states Senators are no longer appointed by state legislatures.",  
                "Amendment 18 prohibits selling, making, or transporting alcohol.",     
                "Amendment 19 gives women the right to vote.",  
                "Amendment 20 fixes the dates of term commencements for Congress.",     
                "Amendment 21 negates Amend. 18, meaning alcohol usage is legal.",      
                "Amendment 22 states Presidents can only serve two terms.",     
                "Amendment 23 provides D.C. residents the right to vote.",      
                "Amendment 24 abolishes Poll Tax in National Elections.",
                "Amendment 25 establish proccess for the President if he/she is unable to serve. VP Power.",    
                "Amendment 26 sets the voting age to 18.",      
                "Amendment 27 focuses on the pay increase or decrease for the Congress."       
        }

                
Last edited on
It would be the same syntax as with an array, use the [] index operator on the vector instance.
1
2
3
std::size_t index;
std::cin >> index;
std::cout << amend_count[index - 1] << std::endl;
Note: consider restricting the values the user can enter.
http://www.LB-Stuff.com/user-input
Topic archived. No new replies allowed.