Redigera

Dela via


_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