943,567 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3566
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Mar 3rd, 2006
0

Dev C++ Hates me

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
Kiba Ookami is offline Offline
66 posts
since Jan 2005
Mar 3rd, 2006
0

Re: Dev C++ Hates me

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:

C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ludesign is offline Offline
9 posts
since Feb 2006
Mar 3rd, 2006
0

Re: Dev C++ Hates me

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:
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
Kiba Ookami is offline Offline
66 posts
since Jan 2005
Mar 3rd, 2006
0

Re: Dev C++ Hates me

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:

C++ Syntax (Toggle Plain Text)
  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:

C++ Syntax (Toggle Plain Text)
  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. }

Reputation Points: 10
Solved Threads: 0
Newbie Poster
ludesign is offline Offline
9 posts
since Feb 2006
Mar 3rd, 2006
0

Re: Dev C++ Hates me

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
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
Kiba Ookami is offline Offline
66 posts
since Jan 2005
Mar 3rd, 2006
0

Re: Dev C++ Hates me

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:

C++ Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ludesign is offline Offline
9 posts
since Feb 2006
Mar 3rd, 2006
0

Re: Dev C++ Hates me

that is half c, half c++. If you want a code in C++, it would look like this:
C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 11
Solved Threads: 0
Newbie Poster
brahle is offline Offline
18 posts
since Mar 2006
Jun 1st, 2009
-2

Re: Dev C++ Hates me

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.
Reputation Points: 3
Solved Threads: 2
Newbie Poster
themaster is offline Offline
18 posts
since May 2009
Jun 1st, 2009
2

Re: Dev C++ Hates me

>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Jun 1st, 2009
1

Re: Dev C++ Hates me

Do yourself a favour: don't use system("pause");
Use
cin.get ();
Last edited by Bladtman242; Jun 1st, 2009 at 6:15 pm.
Reputation Points: 18
Solved Threads: 4
Junior Poster
Bladtman242 is offline Offline
163 posts
since Dec 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: edit a field using c++
Next Thread in C++ Forum Timeline: wxWidgets events Connect or event table?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC