Domanda

Voglio ottenere alcuni dati tra circa 2 indici. Ad esempio, ho stringa: "solo test ..." e ho bisogno di stringa da 2 a 6. dovrei ottenere: 'St TES'.

Quale funzione può fare questo per me?

È stato utile?

Soluzione

Usa substr:

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

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

Si noti che il secondo parametro è la lunghezza della sottostringa, non un indice (la tua domanda è un po 'poco chiaro, dal momento che la stringa 2-6 è in realtà 'st t', non 'st TES').

Altri suggerimenti

substr metodo:

std::string theString = "just testing";
std::string theSubstring = theString.substr(2, 4);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top