Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<cstdlib>
  4. #include<stdio.h>
  5.  
  6. using namespace std;
  7.  
  8. int main ()
  9. {
  10.  
  11.     try
  12.     {
  13.         vector<int> lista;
  14.  
  15.         lista.push_back(1);
  16.         lista.push_back(2);
  17.         lista.push_back(3);
  18.         lista.push_back(4);
  19.         lista.push_back(5);
  20. //        lista.push_back(6);
  21.         int posicao;
  22.  
  23.         cout <<"Imprimir ate a posicao: ";
  24.         do{
  25.             cin >> posicao;
  26.         }while(!(posicao>=0 && posicao <lista.size()));
  27.  
  28.         for(int i = 0; i < posicao; i++)
  29.         {
  30.             cout <<lista[i] <<" ";
  31.         }
  32.  
  33.     }
  34.     catch(...)
  35.     {
  36.         cout <<" Ocorreu um erro"<<endl;
  37.         system("pause");
  38.     }
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement