• Advertisement
Sign in to follow this  

Problem with Dev C++ compiler

This topic is 3906 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm just starting to learn about C++ and I already have an issue with the compiler. Once I compile and run the code, the box goes away so fast that I can barely see it. I tried creating a .bin, .dev and an .exe file for the code, but I get this error: 16 bit MS-DOS Subsystem C:\CPROG~1\C_DEV~1\num.exe The NTVCM CPU has encountered an illegal instruction. Is there another way to make it run the way I want it to, or can some one tell me the command in C++ that makes the program stay up until I press a key. I'm brand new at this after learning Basic and Python for a bit, so it's very different for me. Any help is appreciated. Thank you.

Share this post


Link to post
Share on other sites
Advertisement
You have to tell the program to wait for something, or it runs through your program without letting you see anything.


#include <iostream>

int main(void)
{
// Output string
std::cout << "Hello world!" << std::endl;

// wait for my command!
std::cin.get();
std::cin.get();

return 0;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by Lipponen
You have to tell the program to wait for something, or it runs through your program without letting you see anything.


#include <iostream>

int main(void)
{
// Output string
std::cout << "Hello world!" << std::endl;

// wait for my command!
std::cin.get();
std::cin.get();


return 0;
}

There's no reason to have std::cin.get() twice that I'm aware of. An alternative solution, the more "correct" way according to most, is to run your program from the command prompt. It will remain open after execution.

Share this post


Link to post
Share on other sites
Thanks a lot guys, it works fine now.


#include <iostream>
using namespace std;

int main()
{
cout << "7 + 3 = " << 7 + 3 <<endl;
cout << "7 - 3 = " << 7 - 3 <<endl;
cout << "7 * 3 = " << 7 * 3 <<endl;

cout << "7 / 3 = " << 7 / 3 <<endl;
cout << "7.0 /3.0 = " << 7.0 / 3.0 <<endl;

cout << "7 % 3 = "<< 7 % 3 << endl;

cout << "7 + 3 * 5 = " << 7 + 3 * 5 <<endl;
cout << "(7 + 3) * 5 = " << (7 + 3) * 5 <<endl;

std::cin.get();

return 0;
}

Share this post


Link to post
Share on other sites
Don't artificially pause the program using cin::get() or system() or any of that nonsense. Command-line programs are supposed to be run from the command-line, so either run them from the correct environment as bschneid said or tell your IDE to keep the program open for you.

Dev-C++, like most IDEs, has both "Run with debugging" and "Run without debugging" options. One of those will keep the window open for you, although you may have to adjust some settings in the IDE.

Share this post


Link to post
Share on other sites
Happy to help!

If your doing: using namespace std; you dont have to use std::cin <-. Since youve told the compiler that your using std you can write everything without the std::-part. But I recommend to start by using the std:: to really learn the way of the namespace.

It seems that i accidentaly put two std::cin.get() after eachother :-)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement