C++ cplusplus.com错了吗?指针和字符串文本
在网站上说C++ cplusplus.com错了吗?指针和字符串文本,c++,c++11,visual-c++,c++14,C++,C++11,Visual C++,C++14,在网站上说const char*foo=“hello”当我们输出foo时,它将返回字符串文本的地址,我在家尝试了这个,但我得到了“hello”,当我得到*foo时,我也得到了“hello”,我的问题是网站错了吗 下面的代码解释了一切 const char *foo = "hello"; cout << static_cast<const void *>(foo) << endl; //result is address of "hello" cout
const char*foo=“hello”
当我们输出foo时,它将返回字符串文本的地址,我在家尝试了这个,但我得到了“hello”
,当我得到*foo
时,我也得到了“hello”
,我的问题是网站错了吗
下面的代码解释了一切
const char *foo = "hello";
cout << static_cast<const void *>(foo) << endl; //result is address of "hello"
cout << foo << endl; //result is "hello"
cout << *foo << endl; // result is 'h'
const char*foo=“你好”;
你是怎么输出的?当输出指向char
的指针时,需要几个输出方法来完全按照您描述的那样执行(即,它们输出地址上的内容,而不是地址本身)cout@szd116cout@szd116:我看不出那页上说的是什么。该部分没有说明任何关于输出的内容。@szd116:突出显示的文本是正确的。请注意,它没有说明输出。这意味着指针中存储的值是地址,而不是字母或字符串。它被打印为字符串是解释它的函数的行为。谢谢,现在我明白了
_Myt& __CLR_OR_THIS_CALL operator<<(const void *_Val)
template<class _Traits> inline
basic_ostream<char, _Traits>& operator<<(
basic_ostream<char, _Traits>& _Ostr,
const char *_Val)
template<class _Traits> inline
basic_ostream<char, _Traits>& operator<<(
basic_ostream<char, _Traits>& _Ostr, char _Ch)