How to Make a Receipt in C++ Program

now you have complete the project and want to add some extra feature like document printing or receipt etc. Here in this article we will learn how to print receipt in C++, invoice or student marksheet also. This is the simple demonstration of printing an invoice/receipt.

Remember here, you need to learn File handling concept in C++ before proceeding to below program.

Let’s start,

Document also print date and time which will depend on your system data/time, the following code will be used to fetch the system date and time-

time_t current = time(0);
char* dt = ctime(&current);

Here is the Program,

Print receipt in C++

#include<fstream> // file handling
#include<iomanip> // setw, fetch system date and time

 using namespace std;

 time_t current = time(0);
 char* dt = ctime(&current);

 int main ()
   char title[20]="cppHindiTutorials";
   char student[20]="Rahul";

   int mobile = 1111111;

 ofstream fout("invoice.txt"); // txt file create

 for(int i=0;i<48;i++)

 fout<<endl; // next line 



 fout<<"\n\n\t\tMOBILE NO...........+91";
 fout<<"\n\tDate and Time........";

 fout<<"\n\n\t\t >>Thank You For Visiting<<";


 fout<<setw(30)<<"* * *"<<setw(24)<<"\n";

 for(int j=0;j<48;j++)

return 0;




          MOBILE NO...........+9124242452 

    Date and Time........Fri Jun 11 10:13:20 2021

              >>Thank You For Visiting<< 

                        * * * 


This program will generate a file (invoice.txt)which will be located in you directory where you save all your C++ project.

This is the also an example of text file in C++. Do you know what is text file in C++ read. this article text format vs binary format in C++

  • we can also code in the program where document will go to direct for printing machine and mail to the user.
  • sometime "\t" and "setw()" can misbehave in different system so replace them with each other.
  • in the above program we generated a text file but our requirement we can also generate other formats like pdf, ppt, ms word, html document etc.
  • Above receipt has up and bottom horizontal line but what will be the code if we give complete border left and right(vertical line). maybe you should read this article where print student marksheet in C++.

Did You understand well ?

Like it?

Leave a Reply

Your email address will not be published. Required fields are marked *

Exit mobile version