puts、_putwsputs, _putws

将字符串写入 stdoutWrites a string to stdout.


      int puts(  
   const char *str   
int _putws(  
   const wchar_t *str   


输出字符串。Output string.

返回值Return Value

如果成功,则返回一个非负值。Returns a nonnegative value if successful. 如果 puts 失败,则返回 EOF;如果 _putws 失败,则返回 WEOFIf puts fails, it returns EOF; if _putws fails, it returns WEOF. 如果 str 是 null 指针,则将调用无效的参数处理程序,如参数验证中所述。If str is a null pointer, the invalid parameter handler is invoked, as described in Parameter Validation. 如果允许执行继续,则这些函数将 errno 设置为 EINVAL,并返回 EOFWEOFIf execution is allowed to continue, the functions set errno to EINVAL and return EOF or WEOF.

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


puts 函数将 str 写入标准输出流 stdout,并将字符串的终止空字符 ('\0') 替换为输出流中的换行字符 ('\n')。The puts function writes str to the standard output stream stdout, replacing the string's terminating null character ('\0') with a newline character ('\n') in the output stream.

_putwsputs 的宽字符版本;如果在 ANSI 模式下打开流,则这两个函数的行为相同。_putws is the wide-character version of puts; the two functions behave identically if the stream is opened in ANSI mode. puts 当前不支持到 UNICODE 流中的输出。puts doesn't currently support output into a UNICODE stream.

_putwch写入使用当前控制台区域设置的 Unicode 字符。_putwch writes Unicode characters using the current CONSOLE LOCALE setting.

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

TCHAR.H 例程TCHAR.H routine 未定义 _UNICODE 和 _MBCS_UNICODE & _MBCS not defined 已定义 _MBCS_MBCS defined 已定义 _UNICODE_UNICODE defined
_putts puts puts _putws


例程Routine 必需的标头Required header
puts <stdio.h><stdio.h>
_putws <stdio.h><stdio.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.


C 运行时库的所有版本。All versions of the C run-time libraries.


// crt_puts.c  
/* This program uses puts to write a string to stdout.  

#include <stdio.h>  

int main( void )  
   puts( "Hello world from puts!" );  


Hello world from puts!  

请参阅See Also

流 I/O Stream I/O
fputs、fputws fputs, fputws
fgets、fgetwsfgets, fgetws