fputs、fputwsfputs, fputws

将字符串写入流。Writes a string to a stream.

语法Syntax

int fputs(
   const char *str,
   FILE *stream
);
int fputws(
   const wchar_t *str,
   FILE *stream
);

参数Parameters

strstr
输出字符串。Output string.

streamstream
指向文件结构的指针。Pointer to FILE structure.

返回值Return Value

如果成功,其中每个函数都将返回一个非负值。Each of these functions returns a nonnegative value if it is successful. 出现错误时, fputsfputws返回EOFOn an error, fputs and fputws return EOF. 如果strstream为 null 指针,则这些函数将调用无效参数处理程序,如参数验证中所述。If str or stream is a null pointer, these functions invoke the invalid parameter handler, as described in Parameter Validation. 如果允许执行继续,则这些函数将errno设置为EINVAL ,然后fputs返回EOFfputws返回WEOFIf execution is allowed to continue, these functions set errno to EINVAL and then fputs returns EOF, and fputws returns WEOF.

有关这些代码以及其他错误代码的详细信息,请参阅 _doserrno、errno、_sys_errlist 和 _sys_nerrSee _doserrno, errno, _sys_errlist, and _sys_nerr for more information on these, and other, error codes.

备注Remarks

其中每个函数都将str复制到当前位置的输出中。Each of these functions copies str to the output stream at the current position. fputws会将宽字符参数str 复制为多字节字符字符串或宽字符字符串,具体取决于是以文本模式还是二进制模式打开的。fputws copies the wide-character argument str to stream as a multibyte-character string or a wide-character string according to whether stream is opened in text mode or binary mode, respectively. 函数不会复制终止的 null 字符。Neither function copies the terminating null character.

如果在 ANSI 模式下打开流,则这两个函数行为相同。The two functions behave identically if the stream is opened in ANSI mode. fputs当前不支持输出到 UNICODE 流中。fputs does not currently support output into a UNICODE stream.

一般文本例程映射Generic-Text Routine Mappings

TCHAR.H 例程TCHAR.H routine 未定义 _UNICODE 和 _MBCS_UNICODE & _MBCS not defined 已定义 _MBCS_MBCS defined 已定义 _UNICODE_UNICODE defined
_fputts_fputts fputsfputs fputsfputs fputwsfputws

要求Requirements

函数Function 必需的标头Required header
fputsfputs <stdio.h><stdio.h>
fputwsfputws <stdio.h> 或 <wchar.h><stdio.h> or <wchar.h>

通用 Windows 平台 (UWP) 应用中不支持控制台。The console is not supported in Universal Windows Platform (UWP) apps. 与控制台(stdinstdoutstderr)关联的标准流句柄必须重定向,然后 C 运行时函数才能在 UWP 应用中使用它们。The standard stream handles that are associated with the console—stdin, stdout, and stderr—must be redirected before C run-time functions can use them in UWP apps. 有关其他兼容性信息,请参阅 兼容性For additional compatibility information, see Compatibility.

示例Example

// crt_fputs.c
// This program uses fputs to write
// a single line to the stdout stream.

#include <stdio.h>

int main( void )
{
   fputs( "Hello world from fputs.\n", stdout );
}
Hello world from fputs.

请参阅See also

流 I/OStream I/O
fgets、fgetwsfgets, fgetws
gets、_getwsgets, _getws
puts、_putwsputs, _putws