std::fgets
Da cppreference.com.
![]() | 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. |
Elemento definito nell'header <cstdio> | ||
char*fgets(char*str, int count, FILE *stream ); | ||
Legge a personaggi più count -1 dal flusso di file dato e li memorizza in
str
. La stringa di caratteri prodotta è sempre NULL-terminato. Parsing si arresta se end-of-file di verifica o un carattere di nuova riga viene trovato, nel qual caso str
conterrà quel personaggio capo.Original:
Reads at most count -1 characters from the given file stream and stores them in
str
. The produced character string is always NULL-terminated. Parsing stops if end-of-file occurs or a newline character is found, in which case str
will contain that newline character.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.
Indice |
[modifica]Parametri
str | - | stringa per leggere i caratteri Original: string to read the characters to The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
count | - | la lunghezza di str Original: the length of str The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
stream | - | stream file per leggere i dati Original: file stream to read the data from The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[modifica]Valore di ritorno
str
in caso di successo, NULL su un erroreOriginal:
str
on success, NULL on an errorThe 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.
[modifica]Esempio
#include <iostream>#include <cstdio>#include <cstdlib> int main(){ FILE* tmpf =std::tmpfile();std::fputs("Alan Turing\n", tmpf);std::fputs("John von Neumann\n", tmpf);std::fputs("Alonzo Church\n", tmpf); std::rewind(tmpf);char buf[8];while(std::fgets(buf, sizeof buf, tmpf)!=NULL){std::cout<<'"'<< buf <<'"'<<'\n';}}
Output:
"Alan Tu" "ring " "John vo" "n Neuma" "nn " "Alonzo " "Church "
[modifica]Vedi anche
legge l'input formattato da stdin, un flusso di file o di un buffer Original: reads formatted input from stdin, a file stream or a buffer The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (funzione) | |
legge una stringa di caratteri da stdin Original: reads a character string from stdin The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (funzione) | |
Scrive una stringa di caratteri in un flusso di file Original: writes a character string to a file stream The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (funzione) | |
C documentation for fgets |