如果我有一个功能:
std::string returnString() {
return "Hello, World!";
}
Run Code Online (Sandbox Code Playgroud)
电话:
std::string hello = returnString();
std::cout << hello << std::endl;
Run Code Online (Sandbox Code Playgroud)
生产Hello, World!
.
但是,如果我尝试:
const char* hello = returnString().c_str();
Run Code Online (Sandbox Code Playgroud)
并尝试打印:
for (const char* p = hello; *p; ++p ) {
std::cout << *p;
}
std::cout << std::endl;
Run Code Online (Sandbox Code Playgroud)
它给我一个错误说Invalid read of size 1
,这意味着p是NULL
.
是什么导致了这种行为?
谢谢你的帮助.
我一直在互联网上搜索很多在我的 Gtk 应用程序中使用 3D 图形的方法,并且我找到了 Gtk Glarea,但我找不到任何教程。有人有什么建议吗?