954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Dev C++ Hates me

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.

Kiba Ookami
Junior Poster in Training
66 posts since Jan 2005
Reputation Points: 10
Solved Threads: 1
 

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:

#include <iostream>

using namespace std;

int main() {

     char* name;
     cout << "Enter your name, please: " << endl;
     cin >> name;
     cout << "Your name is: " << cin << endl;

     system("PAUSE");
     return 0;

}


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

thats all :P

i hope this will help you.

ludesign
Newbie Poster
9 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

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:

Kiba Ookami
Junior Poster in Training
66 posts since Jan 2005
Reputation Points: 10
Solved Threads: 1
 

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:

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


it should bename instead of cin.

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

#include <iostream>

using namespace std;

int main() {

	char myName[256];

	cout << "Enter your name, please: " << endl;
    cin.getline(myName, 256);
    cout << "Your name is: " << myName << endl;

    system("PAUSE");
    return 0;

}

:P

ludesign
Newbie Poster
9 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

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

Kiba Ookami
Junior Poster in Training
66 posts since Jan 2005
Reputation Points: 10
Solved Threads: 1
 

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:

#include <iostream>

int main() {

	char myName[256];

	std::cout << "Enter your name, please: " << std::endl;
	std::cin.getline(myName, 256);
	std::cout << "Your name is: " << myName << std::endl;

    system("PAUSE");
    return 0;

}


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 :)

ludesign
Newbie Poster
9 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

that is half c, half c++. If you want a code in C++, it would look like this:

#include <iostream>
#include <string>
using namespace std;

int main( void ) {
  string name;
  char buff[257];
  cout << "Your name: ";
  cin.getline( buff, 257 );
  name = buff;
  cout << "Your name is " << name << endl;
  system( "PAUSE" );
}

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.

brahle
Newbie Poster
18 posts since Mar 2006
Reputation Points: 11
Solved Threads: 0
 

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.

themaster
Newbie Poster
18 posts since May 2009
Reputation Points: 3
Solved Threads: 2
 

>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.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

Do yourself a favour: don't use system("pause");

Use cin.get ();

Bladtman242
Junior Poster
176 posts since Dec 2008
Reputation Points: 18
Solved Threads: 4
 

If DevC++ hates you why not try Code::Blocks?
www.codeblocks.org

evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You