Q:

getting an espacial part of a string in c++

how can I get an especial part of a string or an array or a vector in C++?
in python it is in this way:
a = "hello"     #string
b = [1,2,3,4,5]     #list
a[1:4]     #from index 1 to 4
b[2:4]     #from index 2 to 4

result:
"ell"
[3,4]

is there any such syntax for C++?

A:

You can use the substr method for strings:
 string a = "abcdef";
 string special = a.substr(1,3); // gets bcd

The slice for valarrays:
#include <iostream>
#include <valarray>
using namespace std;

int main ()
{
  valarray<int> foo (5);
  for (int i=0; i<5; ++i) foo[i]=i;

  valarray<int> bar = foo[slice(2,3,1)];

  cout << "slice(2,3,1): ";
  for (size_t n=0; n<bar.size(); n++)
      cout << bar[n] << ' ';
  cout << endl;

  return 0;
}
// Output: slice: 2,3,4

And copy algorithm for vectors and lists:
#include <iostream>
#include <algorithm>
#include <vector>

int main () {
  int myints[]={1,2,3,4,5};
  std::vector<int> v (5);

  std::copy ( myints+1, myints+4, v.begin() );

  std::cout << "v contains:";
  for (std::vector<int>::iterator it = v.begin(); it!=v.end(); ++it)
    std::cout << ' ' << *it;

  std::cout << '\n';

  return 0;
}
// output 2,3,4

