hi im new to c++ and im using bloodshed dev-c++, and i want to know how to set a variable to 50 and then display it on the screen. could someone plz help
hi im new to c++ and im using bloodshed dev-c++, and i want to know how to set a variable to 50 and then display it on the screen. could someone plz help
You're better off reading a tutorial if you don't know this.Code:int var = 50; std::cout << var;
when i write that it says project is not compiled but i did compile it..
Code:#include <iostream> int main() {int var = 50; std::cout << var; return 0;}
the screen just pops up and then disappers...
Dude, read a tutorial on the site. I don't want to sound harsh, but we're not going to give you lessons, we will help you with whatever issue / bug / problem / question -- that isn't asking for us to give you code -- but please show some effort.
Edit: Add this line before 'return 0;'Code:std::cin.get();
Code:#include <iostream> int main() { int var = 50; std::cout << var; system("PAUSE"); return 0; }
This is some evil code, mrafcho001...
thank you!@
Code:#include <iostream> int main() { int var = 50; std::cout << var; system("PAUSE"); return 0; }evil? what does that code do?This is some evil code, mrafcho001...
It's evil only because system() is a portable function (which is good because it is cross-compiler and cross-platform) which takes in non-portable arguments (which means that this line wouldn't work under any OS that doesn't define "PAUSE" -- which is bad). My code on the other hand does more or less the same job and is completely cross-platform and cross-compiler.
The problem is with system("PAUSE"); which has many issues.
- it's operating system dependant. System gets the operating system to spawn another program to do what your asking. You are making the assumption that the pause program exists on the computer, which may not be true.
- it's slow. The operating system has to find the program and run it, when it might not exist.
- it's dangerous. Someone could have replaced the "pause" program, or mapped it to another dangerous program that does god-knows-what, and the program you made can't tell the difference. Therefore hackers can easily get access to other parts of the computer.
so i shouldn't useand useCode:system("pause");right?Code:std::cin.get();
Try to avoid using system() ever, in fact.
Yes.Originally Posted by k1ll3r