Export (0) Print
Expand All
div
eof
Expand Minimize

_cputs, _cputws 

Puts a string to the console.


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 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

Routine Required header Optional header Compatibility

_cputs

<conio.h>

<errno.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

_cputws

<conio.h>

<errno.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

For more compatibility information, see Compatibility in the Introduction.

Libraries

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

Community Additions

ADD
Show:
© 2014 Microsoft