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

str
输出字符串。Output string.

stream
指向 FILE 结构的指针。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 复制到当前位置的输出 streamEach of these functions copies str to the output stream at the current position. fputws 将根据 stream 是以文本模式还是二进制模式打开的来将宽字符自变量 str 作为多字节字符串或宽字符串复制到 streamfputws 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 fputs fputs fputws

要求Requirements

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

通用 Windows 平台 (UWP) 应用中不支持控制台。The console is not supported in Universal Windows Platform (UWP) apps. 与控制台关联的标准流句柄-stdinstdout,和stderr-必须将重定向,然后 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/O Stream I/O
fgets、fgetws fgets, fgetws
gets、_getws gets, _getws
puts、_putwsputs, _putws