Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 command prompt always closes in a milisecond...o.o
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
s0opatro0pa




PostPosted: Sun Apr 08, 2007 10:37 am   Post subject: command prompt always closes in a milisecond...o.o

hmm...well the title says it all...im REEEEEEEEEEEAAAAAAAALLLYY noob so it could easily be a stupid mistake [most probably is]
im using Dev-C++ and after i press F9, it pops up command prompt for a milisecond and BOOM gone... Dev doesnt tell me what im doing wrong too

all help is appreciated! =D
Sponsor
Sponsor
Sponsor
sponsor
md




PostPosted: Sun Apr 08, 2007 10:50 am   Post subject: RE:command prompt always closes in a milisecond...o.o

The problem is that after your program runs and finishes the window closes.

There are two solutions; the bad one is to add a delay to the end of your program (usually by reading some input). The other option is to open a comand promt and run your program from the command line.
s0opatro0pa




PostPosted: Sun Apr 08, 2007 11:05 am   Post subject: Re: command prompt always closes in a milisecond...o.o

o thanks!
but in school, i tried this on c-free and it always gave a "press any button to continue..." at the end of the program. is there anyway that i can do that too?
PaulButler




PostPosted: Sun Apr 08, 2007 1:10 pm   Post subject: RE:command prompt always closes in a milisecond...o.o

Add this to the end of main():

[syntax="c++"]
string a;
cout << "Press enter to continue:";
cin >> a;
[/syntax]

I haven't tried it and I am fairly new to c++, so there may be a better way.
md




PostPosted: Sun Apr 08, 2007 2:05 pm   Post subject: RE:command prompt always closes in a milisecond...o.o

That would work, assuming you are using namespace std; Generally speaking it's a poor idea to do that though, so it would be std::string, std::cout and std::cin.
PaulButler




PostPosted: Sun Apr 08, 2007 2:09 pm   Post subject: Re: RE:command prompt always closes in a milisecond...o.o

md @ Sun Apr 08, 2007 2:05 pm wrote:
That would work, assuming you are using namespace std; Generally speaking it's a poor idea to do that though, so it would be std::string, std::cout and std::cin.


Thanks, that's good to know. Another reason to love c++ Rolling Eyes
s0opatro0pa




PostPosted: Sun Apr 08, 2007 4:27 pm   Post subject: RE:command prompt always closes in a milisecond...o.o

umm..lol..not to sound rude, but i REEEEEEEEEEEEAAAAAAAAAAAAAAALLLLLLLLLLLLLYYY meant that i am REEEEEEAALLY newbie, like one or 2 days that i started this so im still on hello world for the most part. i tried hello world with iostream but it says that it doesnt exist =s
i stoped the thing from closing with the #include conio.h and getch ();

oh so yeaa, can anyone tell me why the iostream doesnt exist??
md




PostPosted: Sun Apr 08, 2007 5:11 pm   Post subject: RE:command prompt always closes in a milisecond...o.o

Can you post your code? Just include it in [ code][/code] tags.
Sponsor
Sponsor
Sponsor
sponsor
s0opatro0pa




PostPosted: Sun Apr 08, 2007 6:19 pm   Post subject: Re: command prompt always closes in a milisecond...o.o

well this is the new one im working on that says iostream wasnt found and string wasnt found either...

code:

#include <iostream>
#include <string>
#include <conio.h>
using namespace std;

int main()
{
    string Name, Age;
   
    cout << "            Welcome\n\n";
    cout << "Please enter your name and age...\n";
    Cout << "Age:";
    cin >> Age ;
    Cout "\nName:"
    cin >> Name;
   
    Cout << " Your name is " << Name << ", and you are " << Age <<", years old."
    getch ();
}
s0opatro0pa




PostPosted: Sun Apr 08, 2007 7:11 pm   Post subject: Re: command prompt always closes in a milisecond...o.o

o i found out that mistake with the inability to find the iostream.........
i saved it as c instead of c++, heh
guess i was more nooby than i thought =p
wtd




PostPosted: Sun Apr 08, 2007 11:50 pm   Post subject: RE:command prompt always closes in a milisecond...o.o

C, C++... it's all text.
bugzpodder




PostPosted: Mon Apr 09, 2007 10:53 am   Post subject: RE:command prompt always closes in a milisecond...o.o

your eyes cant distinguish what happens in a single milliseconds. its more like 50-100 milliseconds.
ericfourfour




PostPosted: Mon Apr 09, 2007 5:37 pm   Post subject: RE:command prompt always closes in a milisecond...o.o

http://www.100fps.com/how_many_frames_can_humans_see.htm
bugzpodder




PostPosted: Mon Apr 09, 2007 7:04 pm   Post subject: Re: command prompt always closes in a milisecond...o.o

informative. but in order for ur os to render the command prompt window, do computations and make it disappear again for your eye to notice, it requires more than one millisecond. not to mention all the context switching between threads (ie os, virus scan, etc)
s0opatro0pa




PostPosted: Tue Apr 10, 2007 6:30 pm   Post subject: Re: command prompt always closes in a milisecond...o.o

lol the milisecond thing was a exaggeration, lol but still some nice information
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 15 Posts ]
Jump to:   


Style:  
Search: