_cputs_cputws

将字符串放到控制台。

重要

此 API 不能用于在 Windows 运行时中执行的应用程序。 有关详细信息,请参阅通用 Windows 平台应用中不支持的 CRT 函数

语法

int _cputs(
   const char *str
);
int _cputws(
   const wchar_t *str
);

参数

str
输出字符串。

返回值

如果成功,则 _cputs 返回 0。 如果函数失败,则返回非零值。

备注

_cputs 函数将由 str 指向的以 null 终止的字符串直接写入控制台。 回车换行符 (CR-LF) 组合不会自动追加到字符串。

此函数验证其参数。 如果 strNULL,则会调用无效的参数处理程序,如参数验证中所述。 如果允许执行继续,则 errno 设置为 EINVAL 并返回 -1。

默认情况下,此函数的全局状态范围限定为应用程序。 若要更改此行为,请参阅 CRT 中的全局状态

一般文本例程映射

Tchar.h 例程 _UNICODE_MBCS 未定义 _MBCS 已定义 _UNICODE 已定义
_cputts _cputs _cputs _cputws

要求

例程 必需的标头 可选标头
_cputs <conio.h> <errno.h>
_cputws <conio.h> <errno.h>

有关兼容性的详细信息,请参阅 兼容性

C 运行时库的所有版本。

示例

// crt_cputs.c
// compile with: /c
// This program first displays a string to the console.

#include <conio.h>
#include <errno.h>

void print_to_console(char* buffer)
{
   int retval;
   retval = _cputs( buffer );
   if (retval)
   {
       if (errno == EINVAL)
       {
         _cputs( "Invalid buffer in print_to_console.\r\n");
       }
       else
         _cputs( "Unexpected error in print_to_console.\r\n");
   }
}

void wprint_to_console(wchar_t* wbuffer)
{
   int retval;
   retval = _cputws( wbuffer );
   if (retval)
   {
       if (errno == EINVAL)
       {
         _cputws( L"Invalid buffer in wprint_to_console.\r\n");
       }
       else
         _cputws( L"Unexpected error in wprint_to_console.\r\n");
   }
}

int main()
{
   // String to print at console.
   // Notice the \r (return) character.
   char* buffer = "Hello world (courtesy of _cputs)!\r\n";
   wchar_t *wbuffer = L"Hello world (courtesy of _cputws)!\r\n";
   print_to_console(buffer);
   wprint_to_console( wbuffer );
}
Hello world (courtesy of _cputs)!
Hello world (courtesy of _cputws)!

另请参阅

控制台和端口 I/O
_putch_putwch