1

I am working on a function which needs me to take the substring of the first two elements of a line.

char those = line.substr(0,1);

When I run the program, it only takes the first element, that's it.

Can you tell me what I'm doing wrong?

Also, how can I tell C++ to get the following elements from an index until the end of the line?

Julio Garcia
  • 393
  • 2
  • 7
  • 22
  • 1
    read the manual :) http://en.cppreference.com/w/cpp/string/basic_string/substr – billz Feb 25 '13 at 03:47
  • 2
    Repeat of http://stackoverflow.com/questions/2477850/c-string-substr-function-problem Looks like the same problem – QuentinUK Feb 25 '13 at 03:49

1 Answers1

1

The second argument is the number of elements to take, not an inclusive index.

porges
  • 30,133
  • 4
  • 83
  • 114