[Not Urgent at all] - Print from c++ Console doesn't work.

This is a discussion on [Not Urgent at all] - Print from c++ Console doesn't work. within the C++ Programming forums, part of the General Programming Boards category; Hi. I have search the internet. and most of the solution I've got is similar to the code below. Problem ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    17

    Question Print from c++ Console doesn't work.

    Hi. I have search the internet. and most of the solution I've got is similar to the code below.

    Problem is, It doesn't work for me.
    i've tested the exe on several PCs, it still doesn't work.
    Please help me to fix this.
    Thanks.

    Code:
    #include <iostream>
    #include <fstream>
    using namespace  std ;
    
    void main()
    {
    	cout<<"Start Printing..."<<endl;
    	ofstream printer;
    	const char EJECT = 0x0c; 
    	printer.open("LPT1");
    	if( !printer )
    	{
    		cerr << "Error! Could not print!";
    		exit(1);
    	}
    
    	printer<<"Hello World!\n"<<endl;
     	cout<<"Hello World, printed."<<endl;
    
    	printer<<EJECT;
    	printer.close();
    	cout<<"Done Printing."<<endl;
    }
    This is the error I had after I run the exe.
    --------------------------- C:\Documents and Settings\zerodevice\Desktop\printer.exe ---------------------------
    C:\Documents and Settings\zerodevice\Desktop\printer.exe
    This application has failed to start because the application configuration is incorrect.
    Reinstalling the application may fix this problem.
    --------------------------- OK ---------------------------

    I am certain my printer and driver works.
    Because they were able to print other documents.
    Last edited by zerodevice; 08-03-2006 at 12:49 PM.

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    First of all, main should return 'int' (although that isn't your problem, your code shouldn't even compile). What IDE/compiler are you using?

    I'm not sure what your problem is, but maybe check that you are statically linking the runtime libraries (in visual studio, you would make sure you aren't compiling with the /MD option). I think I've also seen this message when there was an issue with an application manifest.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    17

    Question

    Hi.
    Thanks for the reply.

    Ok, I've changed it to "int" (I know it doesn't matter.)

    I am using VisualStudio.NET 2005.

    I am unclear about the /MD option.
    Is there anyway you could provide more details?

    thanks.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,832
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Aug 2006
    Posts
    17

    sorry for not reading the page before posting. I will remove it now.
    thanks.

  6. #6
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    http://msdn.microsoft.com/library/de...T.2c_2f.LD.asp

    The bottom of the page explains how to set the option.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  7. #7
    Registered User
    Join Date
    Aug 2006
    Posts
    17

    Question

    Thanks.


    as for the topic, I've taken away the "urgent". but its still says "not urgent at all"?

    just trying to get some help from the internet, coz I've been trying to fix this problem but it didn't worked out.

    Anyway, I've read the page.
    Changed the /MD into /MT.
    Thought It might worked, but resulted errors for main.obj.
    I know it's because of the LIBCMTD.lib.

    However, is there other ways to solve this?
    Coz, I just wanted to know if my code was missing any syntax or anyline I should add?

    thanks.

  8. #8
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    What linker errors are you getting? Maybe you want /MTd or /MLd (if compiling in debug mode)
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  9. #9
    Registered User
    Join Date
    Aug 2006
    Posts
    17

    Question

    Quote Originally Posted by JaWiB
    What linker errors are you getting? Maybe you want /MTd or /MLd (if compiling in debug mode)
    Thanks again.

    I am using /MTd.
    I dont have /MLd in my option.

    erm... lots of errors.

    Error 1 error LNK2005: "public: bool __thiscall std::ios_base:perator!(void)const " (??7ios_base@std@@QBE_NXZ) already defined in msvcprtd.lib(MSVCP80D.dll) main.obj
    Error 2 error LNK2005: "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::endl(class std::basic_ostream<char,struct std::char_traits<char> > &)" (?endl@std@@YAAAV?$basic_ostream@DU?$char_traits@D @std@@@1@AAV21@@Z) already defined in msvcprtd.lib(MSVCP80D.dll) main.obj
    Error 3 error LNK2005: "public: void __thiscall std::basic_ofstream<char,struct std::char_traits<char> >::`vbase destructor'(void)" (??_D?$basic_ofstream@DU?$char_traits@D@std@@@std@ @QAEXXZ) already defined in msvcprtd.lib(MSVCP80D.dll) main.obj
    Error 4 error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >:perator<<(class std::basic_ostream<char,struct std::char_traits<char> > & (__cdecl*)(class std::basic_ostream<char,struct std::char_traits<char> > &))" (??6?$basic_ostream@DU?$char_traits@D@std@@@std@@Q AEAAV01@P6AAAV01@AAV01@@Z@Z) already defined in msvcprtd.lib(MSVCP80D.dll) main.obj
    Error 5 error LNK2005: "public: static bool __cdecl std::char_traits<char>::eq_int_type(int const &,int const &)" (?eq_int_type@?$char_traits@D@std@@SA_NABH0@Z) already defined in msvcprtd.lib(MSVCP80D.dll) main.obj
    Error 6 error LNK2005: "public: static int __cdecl std::char_traits<char>::eof(void)" (?eof@?$char_traits@D@std@@SAHXZ) already defined in msvcprtd.lib(MSVCP80D.dll) main.obj
    Error 7 error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::flush(void)" (?flush@?$basic_ostream@DU?$char_traits@D@std@@@st d@@QAEAAV12@XZ) already defined in msvcprtd.lib(MSVCP80D.dll) main.obj
    Error 8 error LNK2005: "public: void __thiscall std::basic_ios<char,struct std::char_traits<char> >::setstate(int,bool)" (?setstate@?$basic_ios@DU?$char_traits@D@std@@@std @@QAEXH_N@Z) already defined in msvcprtd.lib(MSVCP80D.dll) main.obj
    Error 9 error LNK2005: "public: class std::basic_streambuf<char,struct std::char_traits<char> > * __thiscall std::basic_ios<char,struct std::char_traits<char> >::rdbuf(void)const " (?rdbuf@?$basic_ios@DU?$char_traits@D@std@@@std@@Q BEPAV?$basic_streambuf@DU?$char_traits@D@std@@@2@X Z) already defined in msvcprtd.lib(MSVCP80D.dll) main.obj
    Error 10 error LNK2005: "public: __thiscall std::basic_ofstream<char,struct std::char_traits<char> >::basic_ofstream<char,struct std::char_traits<char> >(void)" (??0?$basic_ofstream@DU?$char_traits@D@std@@@std@@ QAE@XZ) already defined in msvcprtd.lib(MSVCP80D.dll) main.obj
    Error 11 error LNK2005: "public: void __thiscall std::basic_ofstream<char,struct std::char_traits<char> >:pen(char const *,int,int)" (?open@?$basic_ofstream@DU?$char_traits@D@std@@@st d@@QAEXPBDHH@Z) already defined in msvcprtd.lib(MSVCP80D.dll) main.obj
    Error 12 error LNK2005: "public: void __thiscall std::basic_ofstream<char,struct std::char_traits<char> >::close(void)" (?close@?$basic_ofstream@DU?$char_traits@D@std@@@s td@@QAEXXZ) already defined in msvcprtd.lib(MSVCP80D.dll) main.obj
    Error 13 error LNK2005: "public: static unsigned int __cdecl std::char_traits<char>::length(char const *)" (?length@?$char_traits@D@std@@SAIPBD@Z) already defined in msvcprtd.lib(MSVCP80D.dll) main.obj
    Error 14 error LNK2005: "public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputc(char)" (?sputc@?$basic_streambuf@DU?$char_traits@D@std@@@ std@@QAEHD@Z) already defined in msvcprtd.lib(MSVCP80D.dll) main.obj
    Error 15 error LNK2005: "public: bool __thiscall std::ios_base::good(void)const " (?good@ios_base@std@@QBE_NXZ) already defined in msvcprtd.lib(MSVCP80D.dll) main.obj
    Error 16 error LNK2005: "public: void __thiscall std::basic_ostream<char,struct std::char_traits<char> >::_Osfx(void)" (?_Osfx@?$basic_ostream@DU?$char_traits@D@std@@@st d@@QAEXXZ) already defined in msvcprtd.lib(MSVCP80D.dll) main.obj
    Error 17 error LNK2005: "public: int __thiscall std::ios_base::flags(void)const " (?flags@ios_base@std@@QBEHXZ) already defined in msvcprtd.lib(MSVCP80D.dll) main.obj
    Error 18 error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > * __thiscall std::basic_ios<char,struct std::char_traits<char> >::tie(void)const " (?tie@?$basic_ios@DU?$char_traits@D@std@@@std@@QBE PAV?$basic_ostream@DU?$char_traits@D@std@@@2@XZ) already defined in msvcprtd.lib(MSVCP80D.dll) main.obj
    Error 19 error LNK2005: "public: void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Lock(void)" (?_Lock@?$basic_streambuf@DU?$char_traits@D@std@@@ std@@QAEXXZ) already defined in msvcprtd.lib(MSVCP80D.dll) main.obj
    Error 20 error LNK2005: "public: void __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::_Unlock(void)" (?_Unlock@?$basic_streambuf@DU?$char_traits@D@std@ @@std@@QAEXXZ) already defined in msvcprtd.lib(MSVCP80D.dll) main.obj
    Error 21 error LNK2005: "public: int __thiscall std::ios_base::width(void)const " (?width@ios_base@std@@QBEHXZ) already defined in msvcprtd.lib(MSVCP80D.dll) main.obj
    Error 22 error LNK2005: "public: int __thiscall std::ios_base::width(int)" (?width@ios_base@std@@QAEHH@Z) already defined in msvcprtd.lib(MSVCP80D.dll) main.obj
    Error 23 error LNK2005: "public: char __thiscall std::basic_ios<char,struct std::char_traits<char> >::fill(void)const " (?fill@?$basic_ios@DU?$char_traits@D@std@@@std@@QB EDXZ) already defined in msvcprtd.lib(MSVCP80D.dll) main.obj
    Error 24 error LNK2005: "public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,int)" (?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@ std@@QAEHPBDH@Z) already defined in msvcprtd.lib(MSVCP80D.dll) main.obj

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,832
    My suggestion would be to create a nice new empty console project and copy in those few lines into the new project.

    Something's gotten way out of whack in the project if you're having this much trouble compiling what is basically a glorified "hello world" program.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  11. #11
    Registered User
    Join Date
    Aug 2006
    Posts
    17

    Question

    Quote Originally Posted by Salem
    My suggestion would be to create a nice new empty console project and copy in those few lines into the new project.

    Something's gotten way out of whack in the project if you're having this much trouble compiling what is basically a glorified "hello world" program.

    I did what you said but nothing has changed.
    it was fine until I was told to change from "/MDd" to "/MTd".
    and I still think the "/MDd" thing has nothing to do with it.

    There has to be some other ways.

  12. #12
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    I don't know what to say. I've compiled and ran your program in VC++ 2005 with no problems (though I can't say it works correctly since I don't have a printer connected). I haven't been able to replicate the errors you receive.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  13. #13
    Registered User
    Join Date
    Aug 2006
    Posts
    17

    Question

    Quote Originally Posted by JaWiB
    I don't know what to say. I've compiled and ran your program in VC++ 2005 with no problems (though I can't say it works correctly since I don't have a printer connected). I haven't been able to replicate the errors you receive.
    hmm.... that's a funny one.
    Well, thanks anyway.
    I'll try other forums to see if anyone has a solution of a similar problem.

    thanks Salem and JaWiB.

  14. #14
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    I'm using the same compiler, and I got that re-install error before when I was using a lib .... (this is going to make the post sound pointless, but) I can't remember what I did to fix it, nor what the project was ... I thought it was a weird error though.

  15. #15
    Registered User
    Join Date
    Aug 2006
    Posts
    17

    Lightbulb

    Quote Originally Posted by twomers
    I'm using the same compiler, and I got that re-install error before when I was using a lib .... (this is going to make the post sound pointless, but) I can't remember what I did to fix it, nor what the project was ... I thought it was a weird error though.
    XD well, finally someone has something (althought it wasn't a solution, but it's a good start) to prove that I wasn't the only one having problems.

    hmm... Twomers, are you able to get some help for me on this one?
    Coz, it really doesn't make sense. (or most likely because I'm a noob.)

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The Bludstayne Open Works License
    By frenchfry164 in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 11-26-2003, 11:05 AM
  2. How to print Right aligned Text in a console?
    By Aidman in forum C++ Programming
    Replies: 13
    Last Post: 03-09-2003, 10:43 PM
  3. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  4. Just one Question?
    By Irish-Slasher in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2002, 10:19 AM
  5. Console Buffers, Why doesnt this work ?
    By richardnuk in forum C++ Programming
    Replies: 2
    Last Post: 02-01-2002, 04:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21