Made a question from the comment in the topic (@HashCode).

And in general, this book is not old, it is 2007, the author simply decided to write the code in the old way, so that readers can work with old compilers, but my old code does not work, explain pliz, for example, :

#include <iostream.h> int main() { int x = 5; int y = 7; cout << "\n"; cout << x + y << * * << x * y; cout << "\n"; return 0; } 

This is as before, explain how to plizz.

Understood with the command line, well, how to run, and tell me more, how to run normally, but not to close ??

    5 answers 5

    What would the command line not close after execution? Usually they did this:

     #include <conio.h> #include <iostream.h> int main(){ int x = 5; int y = 7; cout << "\n"; cout << x + y << * * << x * y; cout << "\n"; getch(); return 0; } 
    • instead of getch (); also possible system ("pause") - Andrey Kuzmenko
    • I think you need to write _getch (); At least if you are working in Visual Studio - G71
    • getch () or _getch () - this already depends on the version of Visual Studio. The first is for the old versions, the second is for the new ones. - metazet

    Understood with the command line, well, how to run, and tell me more, how to run normally, but not to close ??

    You are cunning, senor! If you have dealt with the command line (console?), Then for Windows you need to add

    getch ();

    in Unix, and the example is written for it, the getch is not needed, the window is not closed, try to set yourself at least a bubunt on a virtual machine, it will go faster and with advantage, IMHO.

      I think it’s probably a matter of C ++ Coding Standards.

       #include <iostream> int main() { int x = 5; int y = 7; std::cout << std::endl; //cout << x + y << * * << x * y; //Эти две звёздочки вообще обрадовали) std::cout << x + y << "Semo text" << x * y; std::cout << std::endl; system("pause"); return 0; } 
         #include <iostream> #include <clocale> using namespace std; int main() { setlocale(LC_ALL, "Russian"); int x = 5; int y = 7; cout<<endl; \\ замисть cout << "\n"; cout << x + y << * * << x * y; cout<<endl; \\ замисть cout << "\n"; return 0; } 
        • one
          The answer is not clear from whom and not related to the question! - Egor Sokolov

        Who told you that the character 'n' does not meet the standards? endl, in addition to the line feed, clears the stream buffer, which is not always necessary.

        To make your program "standard" change the headers:

        include <iostream>

        using namespace std;