_cputs, _cputws

 

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

Puts a string to the console.

System_CAPS_ICON_important.jpg Important

This API cannot be used in applications that execute in the Windows Runtime. For more information, see CRT functions not supported with /ZW.

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

Parameters

str
Output string.

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

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 is not 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.

Generic-Text Routine Mappings

Tchar.h routine_UNICODE and _MBCS not defined_MBCS defined_UNICODE defined
_cputts_cputs_cputs_cputws
RoutineRequired headerOptional header
_cputs<conio.h><errno.h>
_cputws<conio.h><errno.h>

For more compatibility information, see Compatibility.

All versions of the C run-time libraries.

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

Console and Port I/O
_putch, _putwch

Show: