mituri

[C++] zwraca napis od pozycji start do stop z vectora

Oct 1st, 2015
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. /*
  2.  
  3. Napisz funkcję TablicaNaNapis, która tworzy i zwraca napis utworzony przez znaki z tablicy A od znaku pobranego z pozycji start do znaku z pozycji stop.
  4. string TablicaNaNapis(const vector<char> & A, int start, int stop);
  5. Co trzeba założyć o klasie vector i o klasie string, aby zadanie to wykonać w łatwy sposób? (Jakie metody z tych klas są potrzebne?)
  6. Napisz program testujący opracowaną funkcję.
  7.  
  8. */
  9.  
  10. #include "stdafx.h"
  11. #include <queue>
  12. #include <cstdlib>
  13. #include <iostream>
  14. #include <string>
  15. #include <fstream>
  16. #include <stack>
  17.  
  18. using namespace std;
  19.  
  20. string TablicaNaNapis(const vector<char> & A, int start, int stop){
  21. string wynik = "";
  22.  
  23. for(int i = start; i <= stop; i++){
  24. wynik += A[i];
  25. }
  26.  
  27. return wynik.substr(start, stop);
  28. }
  29.  
  30. int _tmain(int argc, _TCHAR* argv[]){
  31.  
  32.  
  33. vector <char> A(5);
  34. A[0] = 'a';
  35. A[1] = 'b';
  36. A[2] = 'c';
  37. A[3] = 'd';
  38. A[4] = 'e';
  39.  
  40. string lancuch = TablicaNaNapis(A,0,4);
  41. cout << lancuch << endl;
  42.  
  43. system ("PAUSE");
  44. }
Advertisement
Add Comment
Please, Sign In to add comment