ESC Sequence for Citizen receipt printer from C++ application

I am trying to print to a receipt printer. I am using the following code:

ofstream print"LPT1"); // open stream

print << "Text will print fine"

print << "\0x0c" //This will produce a form feed...and it also works. \f also produced a form feed......
//the problem is the next line where I try to use the esc command sequence to tell the receipt printer to cut the paper...
print << "\0x1B 0x50 0x01";   //I've tried this line a million different ways and I cannot get it to work.  


For some reason it seems to ignore the escape sequence..In visual basic I can get the printer to cut when I use printer.NewPage .....How do I do this in Visual C++?

Does anyone know how to solve my problem? It would be greatly appreciated!!!!!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try to open the printer in 'binary' mode, e.g."LPT1", ios_base::out | ios_base::binary); // open stream
Jaime OlivaresSoftware ArchitectCommented:
try with this:
print << "\033\120\001";

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jaime OlivaresSoftware ArchitectCommented:
Also you can try with:
print << "\0x1B\0x50\0x01";
But I think not all compilers supports these escape sequences  
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

trstimacAuthor Commented:
This seems to cut the paper:  print << "\033\120\001";
But now I have another problem.

It seems to perform the command before all of the text is written.

I even tried to close the port and then reopen it and just use the cut sequence.

Jaime OlivaresSoftware ArchitectCommented:
Please detail a bit more, your last post is not so clear.
Suggestion, try to use a CR or LF after cutting:

 "\033\120\001\n"  or  "\033\120\001\r"

trstimacAuthor Commented:
My fault!!

Your code does the trick.  

The cuter is after the printer so you have to do a couple of \f (form feeds) at the end and then cut it.

Thank You for you quick response and all of your help!

Jaime OlivaresSoftware ArchitectCommented:
Appears you forgot to close this question...
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.
I will leave the following recommendation for this question in the Cleanup topic area:
Accept: jaime_olivares

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

EE Cleanup Volunteer
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.