Hello, I just have a question about how to find a substring when one has only a string and coordinates for where the data will be? For instance, a string "why,hello", and data that is at the coordinates 4 to 8.

strstr, I obviously cannot use directly, because I have no idea what the string I am searching for is named.

I could use a loop that begins at 4 (just as an example; it would be a variable) and goes until 8, recording each character in a new character array. However, I have previously done this often only to find out that strcat(), memcpy(), or some other predefined function was already made and could probably work better than my code. :o

12 Years
Discussion Span
Last Post by Ancient Dragon

Of course. I hadn't seen that in the cplusplus.com reference for cstring. In fact, cplusplus.com has apparently no documentation for substr at all.

substr() is not a function of cstring -- it is a method of c++ std::string class.

#include <string>

int main()
std::string newstr;
std::string str = "why,hello";

int pos = str.find(',');
if(pos > 0)
  mewstr = str.substr(pos+1);

return 0;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.