C++ Puts() - C++ Standard Library - Programiz

Tutorials Courses Python JavaScript TypeScript SQL HTML CSS C C++ Java R Ruby RUST Golang Kotlin Swift C# DSA

Become a certified C++ programmer.

ENROLL

Popular Tutorials

C++ if...else Statement C++ for Loop Arrays in C++ Strings in C++ C++ Class & Objects Start Learning C++

Popular Examples

Create a simple calculator Check prime number Print the Fibonacci sequence Check if a number is palindrome or not Program to multiply matrix Explore C++ Examples

Reference Materials

iostream cmath cstring ctime View all Programiz Pro Logo

Created with over a decade of experience.

  • Learn
  • Practice
  • Compete
Learn Python Learn HTML Learn JavaScript Learn SQL Learn DSA Learn C Learn C++ Learn Java View all Courses on Programiz Pro Logo Python Basics Python Intermediate C++ Basics C++ Intermediate C++ OOP C Programming Java Basics Java Intermediate Java OOP View all Courses on Programiz Pro Logo Python Challenges JavaScript Challenges Java Challenges C++ Challenges C Challenges View all Challenges on Programiz Pro Logo Learn Practice Compete

Certification Courses

Created with over a decade of experience and thousands of feedback.

Learn Python Learn HTML Learn JavaScript Learn SQL Learn DSA View all Courses on Programiz Pro Logo Learn C Learn C++ Learn Java Python JavaScript TypeScript SQL HTML CSS C C++ Java More languages

Become a certified C++ programmer.

Try Programiz PRO!

Popular Tutorials

C++ if...else Statement C++ for Loop Arrays in C++ Strings in C++ C++ Class & Objects Start Learning C++ All C++ Tutorials

Reference Materials

iostream cmath cstring ctime View all Python JavaScript C C++ Java R Kotlin

Become a certified C++ programmer.

Try Programiz PRO!

Popular Examples

Create a simple calculator Check prime number Print the Fibonacci sequence Check if a number is palindrome or not Program to multiply matrix All C++ Examples

<cstdio> Functions

  • C++ getc()
  • C++ fseek()
  • C++ freopen()
  • C++ fflush()
  • C++ fwrite()
  • C++ fread()
  • C++ puts()
  • C++ putchar()
  • C++ gets()
  • C++ getchar()
  • C++ fgets()
  • C++ fgetc()
  • C++ sscanf()
  • C++ sprintf()
  • C++ snprintf()
  • C++ scanf
  • C++ printf()
  • C++ fscanf()
  • C++ fprintf()
  • C++ fopen()
  • C++ tmpfile()
  • C++ rename()
  • C++ remove()

C++ Tutorials

  • C++ putchar()
  • C++ fgets()
  • C++ gets()
  • C++ fgetc()
  • C++ fflush()
  • C++ tmpfile()
C++ puts()

puts() prototype

int puts(const char *str);

The puts() function takes a null-terminated string str as its argument and writes it to stdout. The terminating null character '\0' is not written but it adds a newline character '\n' after writing the string.

The main difference between fputs() and puts() is the puts() function appends a newline character to the output, while fputs() function does not.

It is defined in <cstdio> header file.

puts() Parameters

str: The string to be written.

puts() Return value

On success, the puts() function returns a non-negative integer. On failure it returns EOF and sets the error indicator on stdout.

Example: How puts() function works

#include <cstdio> int main() { char str1[] = "Happy New Year"; char str2[] = "Happy Birthday"; puts(str1); /* Printed on new line since '/n' is added */ puts(str2); return 0; }

When you run the program, the output will be:

Happy New Year Happy Birthday

Also Read:

  • C++ gets()
Share on: Did you find this article helpful?

Sorry about that.

How can we improve it? Feedback * Leave this field blank

Your builder path starts here. Builders don't just know how to code, they create solutions that matter.

Escape tutorial hell and ship real projects.

Try Programiz PRO
  • Real-World Projects
  • On-Demand Learning
  • AI Mentor
  • Builder Community

Related Library Functions

C++ Library Function

C++ remove()

C++ Library Function

C++ rename()

C++ Library Function

C++ tmpfile()

C++ Library Function

C++ fopen()

Tag » What Is Puts In C