Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这里有未定义的行为吗?
#include <iostream> #include <string> int main() { std::string str = "Hello"; auto p = str.c_str(); char x[] = "sup"; const_cast<char*&>(p) = x; }
不,只有抛弃固有的 const 对象的 const 性并对其进行修改才能给你 UB,否则不会。