Archived

This topic is now archived and is closed to further replies.

C++ and Windows

This topic is 5590 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi, im wondering if anyone knows how to make c++ programs so they appear in a windows, rather then in dos, without using visual c++. I know that with dev-cpp you can make a windows exe program and when you run it it appears in a window, but cout etc don''t work with it. If anyone can help it would be greatly appreciated.

Share on other sites
I am confused by your question, you want your program to run in a window without dos box but you want cout to work? Without the dos box where should the program output to? You''ll have to find some other way than cout to output from a window.
As for the compiling without dos-box, i only know how to do it for gcc (mingw), there you add -mwindows to the linker command line.

Marijn

Share on other sites
quote:
Original post by Razza2003
Hi, im wondering if anyone knows how to make c++ programs so they appear in a windows, rather then in dos, without using visual c++.

Yes.

quote:
I know that with dev-cpp you can make a windows exe program and when you run it it appears in a window, but cout etc don''t work with it.

Yes.

My sarcastic replies aside, what exactly are you asking? You want a Win32 application (with a window, not in the console) yet you want to use cout for output? Not possible. Standard input and output streams, which cin and cout respectively encapsulate, are only defined for console windows. You can redirect them to files, but not to windows. If all you want is to give user notifications, look into MessageBox. Otherwise, you need a dialog box.

Share on other sites
you cannot use cout with windows. you have to use a different function (specifically TextOut...there are others). Any good win32 tutorial/book will show you how to draw text.

extended waranty, how can I lose!

Share on other sites
you can attach a "DOS window" to you GUI application and redirect the default in/output streams to it!

Share on other sites
That''s not true! cout & cerr are definetly defined (I''m not certain about cin) for win32 programs, but their default streambuf just throws the data away.

It is surprisingly easy to redirect cin & cerr to a file.
Conversations: Redirections

  std::ofstream logFile("out.txt");    std::streambuf *outbuf = std::cout.rdbuf(logFile.rdbuf());    std::streambuf *errbuf = std::cerr.rdbuf(logFile.rdbuf());        //use cin & cerr normally        // restore the buffers    std::cout.rdbuf(outbuf);    std::cerr.rdbuf(errbuf);

Now, getting the contents into a window on the screen is a little trickier. Just this week I''ve been looking at various methods for doing this, but have yet to determine the best method.

One way is to pretend the window is a file, and implement a fstreambuf, take over the overflow routine and write the characters into a multiline editbox instead.

Because of the crude hack that I am, I inherited from basic_stringstream, and am polling the contents every 100ms, sucking the stringstream and slapping it into the window.

Not possible... sheesh

Share on other sites
quote:
Original post by Oluseyi
You can redirect [cin and cout] to files, but not to windows.
I see no reason why it couldn''t be done, but it''d be rather complicated.

Share on other sites
Ok, question change, what are the equivilents, if any, or more important, where do i go to learn how to program win32 apps (without vc++).

Share on other sites
quote:
Original post by Razza2003
Ok, question change, what are the equivilents, if any, or more important, where do i go to learn how to program win32 apps (without vc++).

Well in order to answer this we need to know what compiler you intend on using... And even then the answer will be to use google, Im positive there are TONS of win32 programing tutorials out there

Share on other sites
i am not the experienced kind of programmer. but i belive the "Borland C++ Builder" will do the work...

----------------------------------------------------------
I dont have syntax error....
Only logical ones...

1. 1
Rutin
19
2. 2
3. 3
JoeJ
16
4. 4
5. 5

• 26
• 20
• 13
• 13
• 17
• Forum Statistics

• Total Topics
631700
• Total Posts
3001781
×