如何从数组c ++中的字符串中打印第N个字符

时间:2017-10-06 20:37:38

标签: c++ arrays

我对编码非常陌生,我只是有一个简单的问题。 如何从c ++的数组中的字符串中找到第n个字符? 所以例如 {"Hey you" "echo" "lake" "lend" "degree"}n=0 等于"你好" 谢谢!我不会要求提供完整的代码,只是提示从哪里开始。

1 个答案:

答案 0 :(得分: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";