123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|547|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> On Topic -> dev-c++ problem

Page : 1 2 Next
Prev
Sun, 06 Sep 2009, 19:58
jedimastersterli
Background: Recently i bought a book from barns and noble entitled Sams C++ in 24 Hours and after hours of trying to find a registration code for the Borland C++ BuilderX i decided to take advice form one of the previous forms and downloaded the Dev-c++ compiler. The compiler set up without a hitch and seems to be working.I am runing on an antiquated windows xp 2000 but given the age of the compiler they should be 100% compatable.

The problem: When i wrote the first few programs outlined in the book none of them would display to the screen properly. I believe the program works but it only displays the program for one visual cycle and so all i get is a black flash.

If anyone could help me get a long term display it would be apreciated as i am currently parralized in my persuit to learn c++.
Sun, 06 Sep 2009, 20:22
jedimastersterli
i tried the getch() idea but the compiled didn't recognise it. And i dont know how to run or open a dos command line. I am still a beginer to programing
Sun, 06 Sep 2009, 20:47
Cower
i tried the getch() idea but the compiled didn't recognise it. And i dont know how to run or open a dos command line. I am still a beginer to programing

Start -> Run -> cmd

Hopefully you're familiar with basic DOS stuff.
Sun, 06 Sep 2009, 20:57
jedimastersterli
the program im trying to run is

#include <iostream>

int main()
{
std::cout << "Hello World!\n";
return 0;
}

I am running it on Dev-C++ 4.9.9.2

Adding std::cin didn't help either but i would be up for running it in dos. Do you just type it in the same way you do in the compiler?
Sun, 06 Sep 2009, 21:06
Cower
The code is fine. What exactly is the problem? Are you getting a compiler error? And what do you mean by typing it in the compiler..?
Sun, 06 Sep 2009, 21:15
jedimastersterli
the problem is that instead of displaying the text on the screen it flashes it for one visual cycle. so all i can see is a flash of black whenever i compile and run the program
Sun, 06 Sep 2009, 21:21
Cower
So run it in the command prompt like Smith said.
Sun, 06 Sep 2009, 21:30
jedimastersterli
i can get to the command prompt but how do i run the program on it

Sun, 06 Sep 2009, 21:31
Cower
You go to the directory with the program and run it. Sheesh, kids these days and their lack of CLIs.

Maybe read this. terpconnect.umd.edu/~nsw/ench250/dostutor.htm
Sun, 06 Sep 2009, 21:56
jedimastersterli
%( I found the directory but dont know how to access anything on it and even if i did i dont know the syntax for running a program. I am realy confused and feeling stupid. Besides that i realy dont want to have to swithc between compiler and command for every slight alteration of code i have to write.

Is there any way i can change how the my programs are displayed on the command window or a simple piece of code that would keep the command window up for any lenght of? time
Sun, 06 Sep 2009, 22:05
Cower
If you want to just block and wait for input, then add a call to something like std::cin.peek() after writing the output.

Please refer to this just so you know what you're calling before you start using it.
Sun, 06 Sep 2009, 22:26
jedimastersterli
thanks the std::cin.peek() did the trick. I will continue to look for a better way to do it or try to get a differint compiler that works with my computer but as far as right now goes thats a real life saver. In the mean time i will try to learn dos and c++ but i realy apreciate the help.
Sun, 06 Sep 2009, 23:52
shroom_monk
When I used Dev-C++ for this, I stuck system("pause"); at the end (just before return 0. That sticks in DOS's 'Press any key to continue...' text, so you can see what's happening.

Alternatively, use the Code::Blocks IDE. When you run programs in the IDE, it keeps the window open, but when you run the EXE otherwise, it runs as normal.

-=-=-
A mushroom a day keeps the doctor away...

Keep It Simple, Shroom!
Sun, 06 Sep 2009, 23:54
Afr0
std::cin.get() is also a way to do it.
I'm not entirely sure about the technical difference, but I think that cin.get() reads a key from the Console INput (CIN), whereas cin.peek() peeks.
The behaviour of the two should be entirely similar unless you're trying to determine which key was pressed. Not sure why anyone would like to peek() the key though.

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Mon, 07 Sep 2009, 00:12
Cower
When I used Dev-C++ for this, I stuck system("pause"); at the end

This is sort of bad practice, since there's no guarantee 'pause' is going to work for all platforms (generally, this only works for DOS and Windows systems, and it will likely do nothing at all under Posix-compliant systems).

std::cin.get() is also a way to do it.

The only reason I suggested peek() is because you're not actually using the data, so you should leave it in the buffer. That's my opinion, at least.


Mon, 07 Sep 2009, 10:20
shroom_monk
Well, I only used system("pause"); for my own testing programs (such as the ones from the book), since most 'real' programs will have a better way of terminating.

-=-=-
A mushroom a day keeps the doctor away...

Keep It Simple, Shroom!
Mon, 07 Sep 2009, 13:58
blanko1324
I used System("Pause") too, but the book I read taught me to add...



...right before the 'return 0;'.

-=-=-
My Twitter
Mon, 07 Sep 2009, 14:23
Phoenix
Pick the thing which works, and start working on what really matters. After all, you probably won't be using this outside of test projects, and the differences are infinitesimal.
Mon, 07 Sep 2009, 15:21
Afr0
Pick the thing which works, and start working on what really matters. After all, you probably won't be using this outside of test projects, and the differences are infinitesimal.


Wrong!
You need to know about this if you're going to write serversoftware as well.

My current server looks like this:



Only reason the loop is there is to ensure that the threads will work properly. Though it might have been enough to use std::cin.get() on it's own.
I haven't tested it, really.

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Mon, 07 Sep 2009, 15:32
jedimastersterli
Although some of your sugestions workd some of them were not recognized and those that were didnt work with user input. For example if i made a simple adder that requested two numbers and gave a sum the return after each input would mess with the thing holding the window open.

For now i'm using
std::cin >> blah;
where blah is a predefined variable with no deffined use

I know that it bad practice and would cause problems with a real program but for right now it keeps the window open

does anyone know what the problem is because i think the coumpany writing the compiler would have thought of this first and planed accordingly
Mon, 07 Sep 2009, 19:45
Cower
Only reason the loop is there is to ensure that the threads will work properly.
Why not just block until the threads have terminated? Your design makes no sense to me.

You won't need to use any of these little kludges.
This is true. When it comes down to it, kludges are bad.
Tue, 08 Sep 2009, 04:32
JL235
When you run without the 'std::cin >> blah' it is opening a command line window, running your app, printing the output, the app terminates, then the command line window closes. All this occurres in the blink of an eye.

I concur with those above that you just need to learn to run from the command line. As a quick tutorial:
  • Press StartKey + R
  • a run box opens, type cmd and press enter
  • find your program in the explorer and take a note of the address at the top (i.e. C:/users/joe/desktop/my_program)
  • go back to the command line window, type: cd \
  • now type: cd " <directory of your program> " where <directory of your program> is the full path to your compiled programs directory and keep the double quotes (i.e. cd "C:/users/joe/desktop/my_program").
  • type dir and you should see your program listed.
  • type the name of your program (i.e. my_prog.exe) and it'll run.

However most IDEs will allow you to run your program from within the IDE and will automatically redirect the output to a pretty output. This is what I'd advise you learn to use.
Tue, 08 Sep 2009, 15:51
Evil Roy Ferguso
This is not related, but I do consider it to be important:
Dev-C++ has been essentially abandoned since 2005. The version of MinGW (a Windows port of the GCC compiler) that it bundles with it is now extremely out of date and does not support a number of features introduced in GCC 4.x.

You should update the MinGW installation that came with Dev-C++, and probably also consider using a more-up-to-date free IDE, such as Eclipse, CodeBlocks or CodeLite.
Page : 1 2 Next
Prev