puts、_putwsputs, _putws

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

语法Syntax


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

参数Parameters

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.

备注Remarks

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.

在 Windows 2000 和更高版本中,_putwch 使用当前控制台区域设置写入 Unicode 字符。Under Windows 2000 and later, _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

惠?Requirements

例程所返回的值Routine 必需的标头Required header
puts <stdio.h><stdio.h>
_putws <stdio.h><stdio.h>

控制台在 Windows 8.x 应用商店Windows 8.x Store 应用程序中不受支持。The console is not supported in Windows 8.x 应用商店Windows 8.x Store apps. 与控制台 stdinstdoutstderr 关联的标准流句柄必须重定向,然后 C 运行时函数才可以在 Windows 8.x 应用商店Windows 8.x Store 应用中使用它们。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 Windows 8.x 应用商店Windows 8.x Store apps. 有关其他兼容性信息,请参阅 兼容性For additional compatibility information, see Compatibility.

Libraries

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

示例Example

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

#include <stdio.h>  

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

输出Output

Hello world from puts!  

请参阅See Also

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