C.E when using C++ 20
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.
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, # |
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!
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.
96 minutes ago, # |
Check the following blog about this compilation error in C++20.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK