Pregunta

Quiero obtener algunos datos entre unos 2 índices. Por ejemplo, tengo cadena: "haciendo una prueba ..." y necesito cadena desde 2 hasta 6. debo conseguir: 'Tes st'.

¿Qué función puede hacer esto por mí?

¿Fue útil?

Solución

Uso substr:

std::string myString = "just testing...";

std::string theSubstring = myString.substr(2, 6);

Tenga en cuenta que el segundo parámetro es el longitud de la subcadena, no un índice (su pregunta es un poco confuso, ya que la subcadena del 2 al 6 es en realidad 'st t', no 'st tes').

Otros consejos

utilizar el href="http://www.cplusplus.com/reference/string/string/substr/" rel="nofollow noreferrer"> substr método :

std::string theString = "just testing";
std::string theSubstring = theString.substr(2, 4);
scroll top