2017-10-06 115 views
-3

我在編碼方面很新,而且我只是有一個簡短的問題。 如何從C++的數組中的字符串中找到第n個字符? 所以例如 {"Hey you" "echo" "lake" "lend" "degree"}, n=0 將等於「你好」 謝謝!我不會要求完整的代碼,但只是提示從哪裏開始。如何從數組中的字符串中打印第N個字符C++

+2

顯示你已經嘗試,並要求對你被卡住,其中的具體問題。我們不會爲您編寫代碼。 –

+0

歡迎來到stackoverflow.com。請花些時間閱讀[幫助頁面](http://stackoverflow.com/help),尤其是名爲[「我可以問些什麼話題?」]的章節(http://stackoverflow.com/help/)討論話題)和[「我應該避免問什麼類型的問題?」](http://stackoverflow.com/help/dont-ask)。還請[參觀](http://stackoverflow.com/tour)和[閱讀如何提出好問題](http://stackoverflow.com/help/how-to-ask)。最後,請學習如何創建[最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)。 –

+0

1.你好沒有出現在你的數組中。 2.這是一個問題答案網站,不是在正確的方向網站開始。 3.你做過什麼前期工作,試着在谷歌上搜索這個。 –

回答

1

下面是一些例子:

unsigned int n = 3; 
static const char hello[] = "hello"; 
cout << hello[n] << "\n"; 

const std::string apple = "apple"; 
cout << apple[n] << "\n"; 

static const char * many[] = {"These", "are", "many", "strings"}; 
cout << many[n][n] << "\n"; 
cout << many[n] << "\n"; 
相關問題