Dec 11, 2011 at 11:08pm UTC
1. When do I use {} brackets to close things off. I never know when to use them.
2. Can microsoft Express c++ be used to modify existing programs such as video games.if so how do I modify an executable?
Dec 11, 2011 at 11:14pm UTC
1: Use braces to inclose statements. After if/while/else/if else/ function declarations / class declarations ... The first brace opens the statement, the 2nd closes it. e.g.
if(x == 1)
{//Open statement.
//Do some action(s)
} //Close statement
while(x > y)
{
//Do some action(s)
}
int main()
{
//write a program
}
You don't have to use them for statements that are only one line long, but it is good practice to do so, as it makes your code a little more readable.
2) Only if you can get hold of the source code and the appropriate libraries. In short, you cannot modify an .exe file.
Dec 11, 2011 at 11:56pm UTC
I have one more question. How do I keep the console window open? Even if I write something allowing user input the console window closes as soon as the input is entered.
Dec 11, 2011 at 11:58pm UTC
One way to do it is to call system("PAUSE"); before your return 0.
Dec 12, 2011 at 12:44am UTC
Don't use that. This code will suffice:
1 2
cin.sync();
cin.ignore();
Just press enter to close.
If you want to be safe, use this:
1 2 3
cin.clear();
cin.sync();
cin.ignore(std::numeric_limits<std::streamsize>::max());
Last edited on Dec 12, 2011 at 12:45am UTC
Dec 12, 2011 at 1:34am UTC
what about cin.get()? and you forgot about structs and do while loops
Dec 12, 2011 at 1:43am UTC
Last edited on Dec 12, 2011 at 1:49am UTC
Dec 12, 2011 at 3:00am UTC
Athar, what? What is wrong with it? The cin.sync(); gets the new line from the cin >> i; so there should be no problem.