Dev C++ Hates me

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2005
Posts: 66
Reputation: Kiba Ookami is an unknown quantity at this point 
Solved Threads: 1
Kiba Ookami's Avatar
Kiba Ookami Kiba Ookami is offline Offline
Junior Poster in Training

Dev C++ Hates me

 
0
  #1
Mar 3rd, 2006
Whenever I try to run a compiled group of code that should bring up a console, the console just flases onto the screen and is gone...I've copied a few programs from this forum onto it to check and see if its just me but it does it every time.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 9
Reputation: ludesign is an unknown quantity at this point 
Solved Threads: 0
ludesign's Avatar
ludesign ludesign is offline Offline
Newbie Poster

Re: Dev C++ Hates me

 
0
  #2
Mar 3rd, 2006
hi,

you have to make your programs to wait for KeyPress or if you write in windows os then send system("PAUSE"); message.

the other solution is to run all your program from command prompt (cmd.exe)

here is some example code:

  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7. char* name;
  8. cout << "Enter your name, please: " << endl;
  9. cin >> name;
  10. cout << "Your name is: " << cin << endl;
  11.  
  12. system("PAUSE");
  13. return 0;
  14.  
  15. }

you can use cin.get(); instead of system("PAUSE");

thats all

i hope this will help you.
Винаги Ñ?е цели в луната, така и да пропуÑ?неш, пак ще Ñ?и Ñ?ред звездите!
by ludesign
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 66
Reputation: Kiba Ookami is an unknown quantity at this point 
Solved Threads: 1
Kiba Ookami's Avatar
Kiba Ookami Kiba Ookami is offline Offline
Junior Poster in Training

Re: Dev C++ Hates me

 
0
  #3
Mar 3rd, 2006
Much thanks. This must be one of the other changes between the text book I used last year and now.

EDIT: Lol I got a critical error running it after entering my name guess it dosnt' like me still :rolleyes:
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 9
Reputation: ludesign is an unknown quantity at this point 
Solved Threads: 0
ludesign's Avatar
ludesign ludesign is offline Offline
Newbie Poster

Re: Dev C++ Hates me

 
0
  #4
Mar 3rd, 2006
Hi,

excuse me it's all my fall, i was hurry during writing this post because my boss was looking around my desk .. hehehe

so the problem line is:

  1. cout << "Your name is: " << cin << endl;

it should be name instead of cin.

and here is another one example but this time we get the whole line:

  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7. char myName[256];
  8.  
  9. cout << "Enter your name, please: " << endl;
  10. cin.getline(myName, 256);
  11. cout << "Your name is: " << myName << endl;
  12.  
  13. system("PAUSE");
  14. return 0;
  15.  
  16. }

Винаги Ñ?е цели в луната, така и да пропуÑ?неш, пак ще Ñ?и Ñ?ред звездите!
by ludesign
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 66
Reputation: Kiba Ookami is an unknown quantity at this point 
Solved Threads: 1
Kiba Ookami's Avatar
Kiba Ookami Kiba Ookami is offline Offline
Junior Poster in Training

Re: Dev C++ Hates me

 
0
  #5
Mar 3rd, 2006
Ah yes I picked up on it right after I posted, however it still crashes the first block of code. The second runs fine.

Whats with the namespace std thing? Rather, what is std mean in C++?

Also, why did you use an array for variable MyName
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 9
Reputation: ludesign is an unknown quantity at this point 
Solved Threads: 0
ludesign's Avatar
ludesign ludesign is offline Offline
Newbie Poster

Re: Dev C++ Hates me

 
0
  #6
Mar 3rd, 2006
hi,

my english isn't perfect but i'll try to explain you:

using namespace std; telling to your compiler that we will using functions who belong to name space std and then you can use all function who belong to this name space wihtout to telling that to your compiler each time you using them.

for example i'll write you the same program but without defini the name space:

  1. #include <iostream>
  2.  
  3. int main() {
  4.  
  5. char myName[256];
  6.  
  7. std::cout << "Enter your name, please: " << std::endl;
  8. std::cin.getline(myName, 256);
  9. std::cout << "Your name is: " << myName << std::endl;
  10.  
  11. system("PAUSE");
  12. return 0;
  13.  
  14. }

i hope you will understand what i'm trying to explain you

and for the array i prefer to use arrays for more reasons.
it this example i using it to tell my program that name longer that 256 chars is not allowed and the program will display only 256 chars.

that's it ... if you want you can change array size to 5 and to try enter more that 5 chars
Винаги Ñ?е цели в луната, така и да пропуÑ?неш, пак ще Ñ?и Ñ?ред звездите!
by ludesign
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 18
Reputation: brahle is an unknown quantity at this point 
Solved Threads: 0
brahle's Avatar
brahle brahle is offline Offline
Newbie Poster

Re: Dev C++ Hates me

 
0
  #7
Mar 3rd, 2006
that is half c, half c++. If you want a code in C++, it would look like this:
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main( void ) {
  6. string name;
  7. char buff[257];
  8. cout << "Your name: ";
  9. cin.getline( buff, 257 );
  10. name = buff;
  11. cout << "Your name is " << name << endl;
  12. system( "PAUSE" );
  13. }
If you want to get see what is written, you can always use the cmd. If you know to use DOS, using cmd wont be difficult for you.
Revenage is a dish best served cold.
50|2|2Y 4 |34|) 3|\|6|_|5|-|
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 18
Reputation: themaster has a little shameless behaviour in the past 
Solved Threads: 2
themaster themaster is offline Offline
Newbie Poster

Re: Dev C++ Hates me

 
-2
  #8
Jun 1st, 2009
I would suggest you to use the function getch(); in the header file conio.h .

If you do not have the conio.h file you can downoad Visual C++ Express or use the bsic Turbo C++ 3.0.

I use the Turbo C++ 3.0(dont judge it by graphics) as its easier to use.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,661
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 725
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Dev C++ Hates me

 
2
  #9
Jun 1st, 2009
>I use the Turbo C++ 3.0(dont judge it by graphics) as its easier to use.
Then your outdated suggestions are likely to be useless to the majority of people here. C++ has grown since then, and most modern compilers will simply refuse to compile your code.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 116
Reputation: Bladtman242 is an unknown quantity at this point 
Solved Threads: 3
Bladtman242 Bladtman242 is offline Offline
Junior Poster

Re: Dev C++ Hates me

 
1
  #10
Jun 1st, 2009
Do yourself a favour: don't use system("pause");
Use
cin.get ();
Last edited by Bladtman242; Jun 1st, 2009 at 6:15 pm.
Yo god, where do i report a bug?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC