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. 如果放入失败,它将返回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. 如果允许执行继续,则函数将设置errnoEINVAL并返回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.


放入函数写入str写入标准输出流stdout,替换字符串中的终止 null 字符 (\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.

_putws是宽字符版本的放入; 如果在 ANSI 模式下打开流,则两个函数的行为完全相同。_putws is the wide-character version of puts; the two functions behave identically if the stream is opened in ANSI mode. 放入当前不支持输出到 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_putts putsputs putsputs _putws_putws


例程Routine 必需的标头Required header
putsputs <stdio.h><stdio.h>
_putws_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/OStream I/O
fputs、fputwsfputs, fputws
fgets、fgetwsfgets, fgetws