C++ Standard Library C++ STL Library

C++ <cstdio> - puts() Function



The C++ <cstdio> puts() function writes every character of the null-terminated string pointed to by str and one additional newline character '\n' to the output stream stdout. The terminating null-character is not copied to the stream.

fputs() and puts() are equivalent functions except puts() uses stdout as destination and appends a newline character at the end automatically.

Syntax

int puts ( const char * str );

Parameters

str Specify a null-terminated character string to be written.

Return Value

On success, returns a non-negative value. On failure, returns EOF and sets the error indicator ferror().

Example:

The example below shows the usage of puts() function.

#include <cstdio>
 
int main (){
  char str[50] = "Hello World!";

  //prints str
  puts(str);
  
  return 0;
}

The output of the above code will be:

Hello World!

❮ C++ <cstdio> Library