Skip to content

Latest commit

 

History

History
126 lines (98 loc) · 3.58 KB

cputs-cputws.md

File metadata and controls

126 lines (98 loc) · 3.58 KB
description title ms.date api_name api_location api_type topic_type f1_keywords helpviewer_keywords ms.assetid
Learn more about: _cputs, _cputws
_cputs, _cputws
4/2/2020
_cputws
_cputs
_o__cputs
_o__cputws
msvcrt.dll
msvcr80.dll
msvcr90.dll
msvcr100.dll
msvcr100_clr0400.dll
msvcr110.dll
msvcr110_clr0400.dll
msvcr120.dll
msvcr120_clr0400.dll
ucrtbase.dll
api-ms-win-crt-conio-l1-1-0.dll
DLLExport
apiref
cputws
_cputs
_cputws
strings [C++], writing
_cputs function
_cputws function
putting strings to the console
cputs function
console, sending strings to
cputws function
ec418484-0f8d-43ec-8d8b-198a556c659e

_cputs, _cputws

Puts a string to the console.

Important

This API cannot be used in applications that execute in the Windows Runtime. For more information, see CRT functions not supported in Universal Windows Platform apps.

Syntax

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

Parameters

str
Output string.

Return value

If successful, _cputs returns 0. If the function fails, it returns a nonzero value.

Remarks

The _cputs function writes the null-terminated string that's pointed to by str directly to the console. A carriage return-line feed (CR-LF) combination isn't automatically appended to the string.

This function validates its parameter. If str is NULL, the invalid parameter handler is invoked, as described in Parameter validation. If execution is allowed to continue, errno is set to EINVAL, and -1 is returned.

By default, this function's global state is scoped to the application. To change this behavior, see Global state in the CRT.

Generic-text routine mappings

Tchar.h routine _UNICODE and _MBCS not defined _MBCS defined _UNICODE defined
_cputts _cputs _cputs _cputws

Requirements

Routine Required header Optional header
_cputs <conio.h> <errno.h>
_cputws <conio.h> <errno.h>

For more compatibility information, see Compatibility.

Libraries

All versions of the C run-time libraries.

Example

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

See also

Console and port I/O
_putch, _putwch