随笔分类 - C/C++
摘要:int main() { string t1("abcd"); string t2; // x, y指向的地址相同(字符串存放到常量区,看下方图示), 存放x, y本身的地址是不相同的, const char* x = "abcd"; const char* y = "abcd"; char des
阅读全文
摘要:在C++中,以下代码给出了编译器错误: void destruct1 (int * item) { item->~int(); } 这段代码几乎相同,我只是将int定义为另一种类型,并且发生了一些魔术: #include <iostream> using namespace std; typedef
阅读全文
摘要:#include <malloc.h> #include <stdio.h> #include <iostream> #include <string> class Student { public: int id; std::string name; }; int main(int argc, c
阅读全文
摘要:#include <string.h> #include <iostream> using namespace std; struct TestStruct { char *a{nullptr}; char *b{nullptr}; char *c{nullptr}; int id; }; int
阅读全文
摘要:#include <iostream> #include <cassert> using namespace std; int main(int argc, char const* argv[]) { int a = 123; int b = 123; assert(a != b); cout <<
阅读全文
摘要:问题描述今天在写 C++ 代码的时候用上 C++11 的特性,然后发现 VSCode 虽然可以编译通过,但是会在相应位置报红,如下图所示。 并且在编译的时候遇到如下警告: C1.cpp:62:14: warning: 'auto' type specifier is a C++11 extensio
阅读全文