std::num_get::get, std::num_get::do_get
Da cppreference.com.
(Reindirizzamento da cpp/locale/num get/do get)
|
|
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.
La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
<metanoindex/>
<tbody> </tbody>| Elemento definito nell'header <locale>
|
||
public: iter_type get( iter_type in, iter_type end, std::ios_base& str, std::ios_base::iostate& err, bool& v ); iter_type get( iter_type in, iter_type end, std::ios_base& str, std::ios_base::iostate& err, long& v ); iter_type get( iter_type in, iter_type end, std::ios_base& str, std::ios_base::iostate& err, long long& v ); iter_type get( iter_type in, iter_type end, std::ios_base& str, std::ios_base::iostate& err, unsigned short& v ); iter_type get( iter_type in, iter_type end, std::ios_base& str, std::ios_base::iostate& err, unsigned int& v ); iter_type get( iter_type in, iter_type end, std::ios_base& str, std::ios_base::iostate& err, unsigned long& v ); iter_type get( iter_type in, iter_type end, std::ios_base& str, std::ios_base::iostate& err, unsigned long long& v ); iter_type get( iter_type in, iter_type end, std::ios_base& str, std::ios_base::iostate& err, float& v ); iter_type get( iter_type in, iter_type end, std::ios_base& str, std::ios_base::iostate& err, double& v ); iter_type get( iter_type in, iter_type end, std::ios_base& str, std::ios_base::iostate& err, long double& v ); iter_type get( iter_type in, iter_type end, std::ios_base& str, std::ios_base::iostate& err, void*& v ); |
(1) | |
protected: iter_type do_get( iter_type in, iter_type end, std::ios_base& str, std::ios_base::iostate& err, bool& v ); iter_type do_get( iter_type in, iter_type end, std::ios_base& str, std::ios_base::iostate& err, long& v ); iter_type do_get( iter_type in, iter_type end, std::ios_base& str, std::ios_base::iostate& err, long long& v ); iter_type do_get( iter_type in, iter_type end, std::ios_base& str, std::ios_base::iostate& err, unsigned short& v ); iter_type do_get( iter_type in, iter_type end, std::ios_base& str, std::ios_base::iostate& err, unsigned int& v ); iter_type do_get( iter_type in, iter_type end, std::ios_base& str, std::ios_base::iostate& err, unsigned long& v ); iter_type do_get( iter_type in, iter_type end, std::ios_base& str, std::ios_base::iostate& err, unsigned long long& v ); iter_type do_get( iter_type in, iter_type end, std::ios_base& str, std::ios_base::iostate& err, float& v ); iter_type do_get( iter_type in, iter_type end, std::ios_base& str, std::ios_base::iostate& err, double& v ); iter_type do_get( iter_type in, iter_type end, std::ios_base& str, std::ios_base::iostate& err, long double& v ); iter_type do_get( iter_type in, iter_type end, std::ios_base& str, std::ios_base::iostate& err, void*& v ); |
(2) | |
1)
funzione membro pubblica, chiama la
do_get funzione membro della classe più derivata.Original:
public member function, calls the member function
do_get of the most derived class.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
2)
legge i caratteri dal
in iteratore di input e genera il valore del tipo di v, tenendo conto di formattazione bandiere streaming IO da str.flags(), regole di classificazione dei caratteri da std::use_facet<std::ctype<charT>>(str.getloc()), e caratteri di punteggiatura numerici da std::use_facet<std::numpunct<charT>>(str.getloc()). Questa funzione viene chiamata da tutti gli operatori in formato streaming di input quali std::cin >> n;.Original:
reads characters from the input iterator
in and generates the value of the type of v, taking into account IO stream formatting flags from str.flags(), character classification rules from std::use_facet<std::ctype<charT>>(str.getloc()), and numeric punctuation characters from std::use_facet<std::numpunct<charT>>(str.getloc()). This function is called by all formatted input stream operators such as std::cin >> n;.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
La conversione avviene in tre fasi
Original:
Conversion occurs in three stages
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Fase 1: selezione specificatore di conversione
- I / O flags formato sono ottenuti, come perOriginal:I/O format flags are obtained, as if byThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
fmtflags basefield = (str.flags() & std::ios_base::basefield);fmtflags boolalpha = (str.flags() & std::ios_base::boolalpha);
- Se il tipo di
vè di tipo intero, la prima scelta applicabili delle seguenti cinque è selezionato:Original:If the type ofvis an integer type, the the first applicable choice of the following five is selected:The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- Se
basefield == oct, utilizzerà specificatore di conversione%oOriginal:Ifbasefield == oct, will use conversion specifier%oThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Se
basefield == hex, utilizzerà specificatore di conversione%XOriginal:Ifbasefield == hex, will use conversion specifier%XThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Se
basefield == 0, utilizzerà specificatore di conversione%iOriginal:Ifbasefield == 0, will use conversion specifier%iThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Se il tipo di
vè firmato, utilizzerà specificatore di conversione%dOriginal:If the type ofvis signed, will use conversion specifier%dThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Se il tipo di
vnon è firmato, userà specificatore di conversione%uOriginal:If the type ofvis unsigned, will use conversion specifier%uThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- Per i tipi interi, modificatore di lunghezza viene aggiunto alla specifica di conversione, se necessario:
hpershorteunsigned short,lperlongeunsigned long,llperlong longeunsigned long longOriginal:For integer types, length modifier is added to the conversion specification if necessary:hforshortandunsigned short,lforlongandunsigned long,llforlong longandunsigned long longThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Se il tipo di
vèfloat, userà specificatore di conversione%gOriginal:If the type ofvisfloat, will use conversion specifier%gThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Se il tipo di
vèdouble, userà specificatore di conversione%lgOriginal:If the type ofvisdouble, will use conversion specifier%lgThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Se il tipo di
vèlong double, userà specificatore di conversione%LgOriginal:If the type ofvislong double, will use conversion specifier%LgThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Se il tipo di
vèvoid*, userà specificatore di conversione%pOriginal:If the type ofvisvoid*, will use conversion specifier%pThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Se il tipo di
vèbooleboolalpha==0, procede come se il tipo divèlong, tranne per il valore da memorizzare invin fase 3.Original:If the type ofvisboolandboolalpha==0, proceeds as if the type ofvislong, except for the value to be stored invin stage 3.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Se il tipo di
vèbooleboolalpha!=0, il seguente sostituisce fasi 2 e 3:Original:If the type ofvisboolandboolalpha!=0, the following replaces stages 2 and 3:The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - * Caratteri successivi ottenuta dalla
initeratore di input vengono confrontati con le sequenze di caratteri ottenutistd::use_facet<std::numpunct<charT>>(str.getloc()).falsename()estd::use_facet<std::numpunct<charT> >(str.getloc()).truename()solamente come necessario per identificare la corrispondenza univoca. Iliniteratore di input viene confrontatoendsolo quando necessario per ottenere un carattere.Original:* Successive characters obtained from the input iteratorinare matched against the character sequences obtained fromstd::use_facet<std::numpunct<charT>>(str.getloc()).falsename()andstd::use_facet<std::numpunct<charT> >(str.getloc()).truename()only as necessary as to identify the unique match. The input iteratorinis compared toendonly when necessary to obtain a character.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - * Se la sequenza bersaglio è corrispondenza univoca,
vviene impostato al valoreboolcorrispondente. In caso contrario, viene memorizzato infalseve std::ios_base::failbit viene assegnato aerr. Se corrispondenza univoca non è stato trovato prima dell'ingresso chiuso (in==end),err|=std::ios_base::eofbitviene eseguito.Original:* If the target sequence is uniquely matched,vis set to the correspondingboolvalue. Otherwisefalseis stored invand std::ios_base::failbit is assigned toerr. If unique match could not be found before the input ended (in==end),err|=std::ios_base::eofbitis executed.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Fase 2: estrazione carattere
- Se
in==end, Fase 2 è terminata immediatamente, non vengono estratti altri caratteriOriginal:Ifin==end, Stage 2 is terminated immediately, no further characters are extractedThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Il carattere successivo viene estratto dal
income perchar_type ct = *in;Original:The next character is extracted frominas if bychar_type ct = *in;The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - * Se il carattere corrisponde a una delle
"0123456789abcdefxABCDEFX+-", allargato a char_type dell'unità locale come perstd::use_facet<std::ctype<charT>>(str.getloc()).widen(), viene convertito nel corrispondentechar.Original:* If the character matches one of"0123456789abcdefxABCDEFX+-", widened to the locale's char_type as if bystd::use_facet<std::ctype<charT>>(str.getloc()).widen(), it is converted to the correspondingchar.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - * Se il carattere corrisponde al separatore decimale punto (
std::use_facet<std::numpunct<charT>>(str.getloc()).decimal_point())), è sostituito da'.'.Original:* If the character matches the decimal point separator (std::use_facet<std::numpunct<charT>>(str.getloc()).decimal_point())), it is replaced by'.'.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - * Se il carattere corrisponde al separatore di migliaia (
std::use_facet<std::numpunct<charT>>(str.getloc()).thousands_sep()) e la separazione delle migliaia è usato da tuttestd::use_facet<std::numpunct<charT>>(str.getloc()).grouping().length() != 0, quindi se il'.'punto decimale non è ancora stata accumulata, la posizione del carattere viene rememebered, ma il carattere è altrimenti ignorato. Se il punto decimale è già stato accumulato, il carattere viene scartato e fase 2 termina.Original:* If the character matches the thousands separator (std::use_facet<std::numpunct<charT>>(str.getloc()).thousands_sep()) and the thousands separation is in use at allstd::use_facet<std::numpunct<charT>>(str.getloc()).grouping().length() != 0, then if the decimal point'.'has not yet been accumulated, the position of the character is rememebered, but the character is otherwise ignored. If the decimal point has already been accumulated, the character is discarded and Stage 2 terminates.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - * In ogni caso, il controllo viene effettuato se il
charottenuta dai passaggi precedenti è ammesso nel campo di immissione che sarebbe analizzato da std::scanf data l'indicatore di conversione selezionato nella fase 1. Se è consentito, viene accumulata in un buffer temporaneo e Stage 2 ripete. Se non è consentito, fase 2 termina.Original:* In any case, the check is made whether thecharobtained from the previous steps is allowed in the input field that would be parsed by std::scanf given the conversion specifier selected in Stage 1. If it is allowed, it is accumulated in a temporary buffer and Stage 2 repeats. If it is not allowed, Stage 2 terminates.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Fase 3: conversione e lo stoccaggio
- La sequenza di
chars accumulati nella fase 2 viene convertito in un valore numericoOriginal:The sequence ofchars accumulated in Stage 2 is converted to a numeric valueThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - * L'ingresso viene analizzato come per std::scanf con lo specificatore di conversione selezionato nella fase 1 (fino al c++11)Original:* The input is parsed as if by std::scanf with the conversion specifier selected in Stage 1 (fino al c++11)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - * L'ingresso viene analizzato come per std::strtoll per intero con segno
v, std::strtoull pervnumero intero senza segno, o std::strtold per virgola mobilev(dal C++11)Original:* The input is parsed as if by std::strtoll for signed integerv, std::strtoull for unsigned integerv, or std::strtold for floating-pointv(dal C++11)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Se la funzione di conversione non riesce a convertire l'intero campo, il
0valore viene memorizzato inv(dal C++11)Original:If the conversion function fails to convert the entire field, the value0is stored inv(dal C++11)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Se i risultati delle funzioni di conversione in un valore positivo troppo grande per il tipo di
v, il valore più positivo rappresentabile è memorizzato inv(dal C++11)Original:If the conversion function results in a positive value too large to fit in the type ofv, the most positive representable value is stored inv(dal C++11)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Se i risultati delle funzioni di conversione in un valore negativo troppo grande per il tipo di
v, il valore più negativo rappresentabile è memorizzato inv(dal C++11)Original:If the conversion function results in a negative value too large to fit in the type ofv, the most negative representable value is stored inv(dal C++11)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - In ogni caso, se la funzione di conversione non riesce std::ios_base::failbit è assegnato
errOriginal:In any case, if the conversion function fails std::ios_base::failbit is assigned toerrThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Altrimenti, il risultato numerico della conversione è memorizzato in
vOriginal:Otherwise, the numeric result of the conversion is stored invThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - * Se il tipo di
vèboole boolalpha non è impostato, se il valore da memorizzare è0,falseviene memorizzato, se il valore da memorizzare è1,trueviene memorizzato, per qualsiasi std::ios_base::failbit altro valore viene assegnatoerr.Original:* If the type ofvisbooland boolalpha is not set, then if the value to be stored is0,falseis stored, if the value to be stored is1,trueis stored, for any other value std::ios_base::failbit is assigned toerr.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Dopo questo, raggruppamento cifre è selezionata. Se la posizione di uno dei separatori di migliaia scartati nella fase 2 non corrisponde al raggruppamento fornito da
std::use_facet<std::numpunct<charT>>(str.getloc()).grouping(), std::ios_base::failbit è assegnatoerr.Original:After this, digit grouping is checked. if the position of any of the thousands separators discarded in Stage 2 does not match the grouping provided bystd::use_facet<std::numpunct<charT>>(str.getloc()).grouping(), std::ios_base::failbit is assigned toerr.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. - Se Fase 2 si è concluso con la prova
in==end,err|=std::ios_base::eofbitviene eseguito per impostare il bit eof.Original:If Stage 2 was terminated by the testin==end,err|=std::ios_base::eofbitis executed to set the eof bit.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Valore di ritorno
in
Note
In C + +98 / C + 03, se si verifica un errore,
v rimane invariato. In C + 11, è impostato ad un valore come descritto sopra.Original:
In C++98/C++03, if an error occurs,
v is left unchanged. In C++11, it is set to a value as described above.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Esempio
| This section is incomplete Reason: no example |
Vedi anche
estratti i dati formattati Original: extracts formatted data The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (metodo pubblico) | |