ho questa stringa:C++ sottostringa di restituire i risultati errati
std::string date = "20121020";
sto facendo:
std::cout << "** Date: " << date << "\n";
std::cout << "Year: " << date.substr(0,4) << "\n";
std::cout << "Month: " << date.substr(4,6) << "\n";
std::cout << "Day: " << date.substr(6,8) << "\n";
Ma nel mese di ottenere:
** Date: 20121020
Year: 2012
Month: 1020
Day: 20
Si noti che il mese dovrebbe essere 10
, non 1020
. Le posizioni sono corrette, provato di tutto, cioè che sta fallendo?
Secondo argomento è la lunghezza della sottostringa, non l'indice finale. –
'std :: string date = 20121020' è sintatticamente errato. Intendevi 'std :: string date =" 20121020 "'? –
@DanielFischer, potrebbe anche essere una risposta, perché è esattamente questo il problema. – Chad