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. 如果put 失败,则返回EOF;如果 _putws失败,则返回WEOFIf puts fails, it returns EOF; if _putws fails, it returns WEOF. 如果str为空指针,则将调用无效参数处理程序,如参数验证中所述。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.


Put函数将 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. put当前不支持到 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. 与控制台、 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.


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