Share via


_cputs、_cputws

更新 : 2007 年 11 月

文字列をコンソールに出力します。

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

パラメータ

  • str
    出力する文字列。

戻り値

正常に実行された場合、_cputs は 0 を返します。エラーが発生した場合は、0 以外の値を返します。

解説

_cputs 関数は、str が指す NULL で終わる文字列をコンソールに直接書き込みます。キャリッジ リターンとラインフィード (CR-LF: carriage return–line feed) の組み合わせが、文字列に自動的に追加されることはありません。

この関数は、パラメータを検証します。str が NULL の場合は、「パラメータの検証」に説明されているように、無効なパラメータ ハンドラが呼び出されます。実行の継続が許可された場合、errnoEINVAL に設定され、関数から -1 が返されます。

汎用テキスト ルーチンのマップ

Tchar.h のルーチン

_UNICODE および _MBCS が未定義の場合

_MBCS が定義されている場合

_UNICODE が定義されている場合

_cputts

_cputs

_cputs

_cputws

必要条件

ルーチン

必須ヘッダー

オプション ヘッダー

_cputs

<conio.h>

<errno.h>

_cputws

<conio.h>

<errno.h>

互換性の詳細については、「C ランタイム ライブラリ」の「互換性」を参照してください。

ライブラリ

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. 
   // Note 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)!

参照

参照

コンソール入出力とポート入出力

_putch、_putwch