小编Pep*_*ork的帖子

了解变量分配

你能帮我理解存储变量的位置(堆栈,堆,静态内存)吗?我怎样才能确定它?我的意思是不直观,但我想在screan上印上一些标志.可能吗?

到目前为止,我试图通过打印地址来查看变量的存储位置.但这并没有给我太多帮助.你能看看并给我一些建议.如果我犯了一个错误(请参阅我对该计划的评论),请告诉我这个问题.

#include "stdafx.h"
#include <iostream>
using namespace std;

int * p1 = new int [3]; // Static memory as it is a global array;
namespace P {int * p2 = new int[3];} // Static memory as it is a namespace; 
namespace {int * p3 = new int[3];} // Static memory as it is a namespace;
using namespace P;

int _tmain(int argc, _TCHAR* argv[])
{
    int * p4 = new int[3]; // Heap as there is a new operator.
    static …
Run Code Online (Sandbox Code Playgroud)

c++

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

C++中的char*和cin

我想使用cin向char*变量输入一个不确定长度的字符串;

我可以做这个:

char * tmp = "My string";
cout << tmp << endl;
system("pause");
Run Code Online (Sandbox Code Playgroud)

它完美地运作.

但我没有做到这一点:

 char * tmp
 cin >> tmp;
Run Code Online (Sandbox Code Playgroud)

你能告诉我一个什么是错的"

c++ arrays cin

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

c ++:#include和不同的文件类型

我莫名其妙地无法抓住这个想法,阅读文档并没有帮助我.

我的问题是:

  1. 当我包含头文件#include"general.h"时,在我的项目目录中有两个文件general.h和general.cpp,这是否意味着我预编译器会自动找到.cpp文件?
  2. 我可以包含没有扩展名的文件:#include"general"?
  3. 我可以包含没有任何头文件的文件:#include"general.cpp"?
  4. 我可以包含一个txt文件:#include"general.txt"?

我在Visual Studio 2010中尝试了这一切.至少没有语法错误.但我想解释一下.所以,我希望你会善良并帮助我.

c++

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

c ++:为什么char c = 0xff和int n = c + 1得到100的结果?

我只是想知道为什么n = 0?

char c = 0xff;
    int n = c+1;
    cout << n << endl;
    system("pause");
Run Code Online (Sandbox Code Playgroud)

1)c = 0xff
2)0xff + 1 = 0x100.

你能解释一下吗?

c++

-7
推荐指数
2
解决办法
2826
查看次数

标签 统计

c++ ×4

arrays ×1

cin ×1