std::fgets
De cppreference.com
![]() |
Esta página se ha traducido por ordenador/computador/computadora de la versión en inglés de la Wiki usando Google Translate.
La traducción puede contener errores y palabras aparatosas/incorrectas. Planea sobre el texto para ver la versión original. Puedes ayudar a corregir los errores y mejorar la traducción. Para instrucciones haz clic aquí. |
Definido en el archivo de encabezado <cstdio>
|
||
char *fgets( char *str, int count, FILE *stream ); |
||
Lee en la mayoría de los personajes count - 1 de la secuencia de archivo determinado y los almacena en
str
. La cadena de caracteres producida es siempre NULL-terminado. Procesamiento se detiene si al final de su archivo se produce o un carácter de nueva línea se encuentra, en cuyo caso str
contendrá ese carácter de nueva línea .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.
Contenido |
[editar] Parámetros
str | - | String para leer los caracteres
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 longitud de
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 | - | archivo de flujo para leer los datos
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. |
[editar] Valor de retorno
str
en caso de éxito, NULL en un errorOriginal:
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.
[editar] Ejemplo
Ejecuta este código
#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'; } }
Salida:
"Alan Tu" "ring " "John vo" "n Neuma" "nn " "Alonzo " "Church "
[editar] Ver también
lee la entrada con formato desde stdin, una secuencia de archivo o un tampón 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. (función) | |
lee una cadena de caracteres de 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. (función) | |
escribe una cadena de caracteres en una secuencia de archivo 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. (función) | |
Documentación de C para fgets
|