小编Swa*_*ari的帖子

功能范围是什么意思?

功能范围是什么意思?

我理解变量的范围.当我们讨论函数的范围时,它是指结构(类)中的函数还是我们在main()C/C++程序中调用的常规函数​​的范围?

c++ scope

6
推荐指数
2
解决办法
8706
查看次数

malloc for string pointers:怎么会是灾难性的?

这个Informit C++指南中,我读到了这个:

使用malloc()创建一个非POD对象会导致未定义的行为:

//disastrous!
std::string *pstr =(std::string*)malloc(sizeof(std::string));
Run Code Online (Sandbox Code Playgroud)

我在这里不明白2点:

  • 指针是POD.那么为什么它在这里被称为非POD?(也许我必须更好地了解POD.)
  • 怎么会这么灾难性的?(我想我必须理解字符串Internals.)

请解释!

c++ string malloc

3
推荐指数
1
解决办法
1779
查看次数

std :: cout如何工作

可能重复:
cout中的cout << cout和cout <<和cout有什么区别?

我意外地发现:

cout << cout;
Run Code Online (Sandbox Code Playgroud)

输出是一些地址.这个地址是什么意思,为什么会显示出来?
我在看这个问题.

谢谢

c++ cout

3
推荐指数
1
解决办法
1870
查看次数

删除指针的问题(指向的内容)

如何删除我在下面的代码中指定的指针:

char* ptr;
ptr=new char(65);   // memory for one char is created and is assigned 'A'
strcpy(ptr,"asdf"); // how can string of length 4 chars are copied
delete ptr;         // why am I getting debug error of Heap corruption detected
Run Code Online (Sandbox Code Playgroud)

我正在使用Visual C++ 2005

c++ delete-operator

1
推荐指数
1
解决办法
197
查看次数

标签 统计

c++ ×4

cout ×1

delete-operator ×1

malloc ×1

scope ×1

string ×1