![](/img/trans.png)
[英]Use of std::regex_iterator<std::string::iterator> according to CPlusPlus.com
[英]is cplusplus.com wrong? Pointers and string literals
在這個頁面的“指針和字符串文字”部分,網站說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'
cout << static_cast<const void *>(foo)
調用以下函數。
_Myt& __CLR_OR_THIS_CALL operator<<(const void *_Val)
cout << foo
調用以下函數。
template<class _Traits> inline
basic_ostream<char, _Traits>& operator<<(
basic_ostream<char, _Traits>& _Ostr,
const char *_Val)
cout << *foo
調用以下函數。
template<class _Traits> inline
basic_ostream<char, _Traits>& operator<<(
basic_ostream<char, _Traits>& _Ostr, char _Ch)
注意上面調用函數的最后一個參數。
以下快照來自http://www.cplusplus.com/doc/tutorial/pointers/ 。 內容是對的,沒有錯。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.