C++ 打印指针的值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2485565/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C++ print value of a pointer
提问by user69514
I have an array of double pointers, but every time I try do print one of the values the address gets printed. How do I print the actual value?
我有一个双指针数组,但是每次我尝试打印地址时都会打印一个值。如何打印实际值?
cout << arr[i] ? cout << &arr[i] ? they both print the address
cout << arr[i] ? cout << &arr[i] ? 他们都打印地址
Does anyone know?
有人知道吗?
回答by Matthew Flaschen
If it's really an array of (initialized) double pointers, i.e.:
如果它真的是一个(初始化的)双指针数组,即:
double *arr[] = ...
// Initialize individual values
all you need is:
所有你需要的是:
cout << *arr[i];
回答by Thomas Bonini
cout << *(arr[i]);
cout << *(arr[i]);
回答by Anatoly Fayngelerin
cout << *(arr[i]) will print the value.
cout << *(arr[i]) 将打印值。
回答by Jay Walker
If "arr" is declared as
如果“arr”被声明为
double* arr[..];
Then you would use:
然后你会使用:
cout << *(arr[i])