N
N
nickita1782016-10-18 20:43:10
C++ / C#
nickita178, 2016-10-18 20:43:10

I can not understand the book Herbert Schildt C ++. Is the error in the book or in VS?

There is a book Herbert Schildt C ++ basic course. On page 14, the simplest first program. I wrote it, compiled it, ran it, but the window instantly disappears. I searched the Internet and realized that I need to write cin.get (). So is it wrong in the book or in the Visual Studio 2015 program itself? Give answer.
Here is the program
#include
int main()
{
using namespace std;
cout << "Hello";
return 0;
}

Answer the question

In order to leave comments, you need to log in

6 answer(s)
V
Vitaly, 2016-10-18
@vt4a2h

It's not a mistake. The program started, printed something and returned 0. VS behaves correctly and so does the program. No one in books on the pluses of a general orientation will focus on a specific IDE, OS, or compiler. At least that's how it should be.
Try to run your program from the console, and then the black window will not close, or configure the IDE so that it does not close the console. I think that it will google one or two.

A
Anton Zhilin, 2016-10-18
@Anton3

This is a feature of the studio. To prevent the window from closing immediately, you need to add in the settings:
Properties>Configuration Properties>Linker>System=Console
Answering the question, there is no error in the book, for example, under Linux this nuance is not.

1
15432, 2016-10-18
@15432

The program honestly prints the inscription (cout << "Hello") and closes (return 0)
No errors.
You can before return 0; add an infinite loop while(1); and make sure

R
Rou1997, 2016-10-18
@Rou1997

Both in the book and in VS it is wrong that they did not take into account this subtlety, but Schildt's fault is much greater.

N
Nexeon, 2016-10-18
@MrNexeon

1. There is no mistake, this is purely a subtlety, and attention should not be focused on it.
2. The line output "Hello"to the console is very fast, so the window closes instantly.
ps I recommend reading C ++ Basic course, Lippman instead of Schildt

A
abcd0x00, 2016-10-19
@abcd0x00

No need to write system("pause") or cin.get(). You just need to make a shortcut to cmd.exe in the program folder and erase the path to the working directory in its properties. So the console will be launched directly in this folder, it will already be possible to execute the program in it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question