Q:

Explain what this loop does and whether it is a good use of assert

0

Explain what this loop does and whether it is a good use of assert:

string s;
while (cin >> s && s != sought) { } // empty body
assert(cin);

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

The loop are used to keep reading string from the input until `sought` found. It is a bad idea to use `assert` check whether `cin` is in an error state. Because when the program compiled with `NDEBUG` preprocessor variable, the statement would not be excuted.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now