7

C.E when using C++ 20

 2 years ago
source link: http://codeforces.com/blog/entry/96895
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
By Lemur95, history, 112 minutes ago, In English

Hello CF community,

I just stumbled upon this weird (at least for me) behaviour. I was trying to solve 1605C - Dominant Character, I set the compiler to C++ 20 and sent this code 135233345 but got C.E. for whatever reason. Then I thought of switching back to C++ 17 and this time I got accepted 135233454 (Note that it is the same code).

Can someone tell me why this is happening?

103 minutes ago, # |

The Click link at the bottom of the failed compilation seems to have enough details about the reason of the compilation error.

102 minutes ago, # |

  1. The "whatever reason" for compilation error is available at the bottom of the submission page. Generally, on error, compiler messages should be available on any modern testing system. Do make use of that!

  2. The error itself is that the >> operator no longer accepts a raw char pointer. Relevant information and reasoning can be found here, for example. In a nutshell: reading a string into a raw char pointer is unsafe; it's safer to read into an char array of known length, and stop before that length is exceeded, taking the null terminator into account. All in all, good to see some safety features in C++20, it's about time they appeared.

  • 93 minutes ago, # ^ |

    I did check the compiler message and thought that it had something to do with the variable's name, which made no sense. Good to know that reading a raw char pointer is not safe, thanks!

96 minutes ago, # |

Check the following blog about this compilation error in C++20.

Can't use std::cin with char* or char array in C++20


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK