一维 std::string 数组在技术上是矩阵吗?

Are one dimensional std::string arrays technically a matrix?

我正在写一些代码,只是想完善一些编程抽象思想。这是我所在的位置和我要问的问题:

在 c++ 中,我们有数据类型 std::string。这种数据类型基本上是具有成员函数和变量的高级指针。

当您像这样使用字符串数组时:std::string test[5]; 字符串在技术上会被标记为矩阵吗?我想知道这是因为使用 std::string 您可以使用以下方式指定常规字符串的各个字符:

std::string hello = "Hello"; std::cout<<hello[3];

输出将是:

l

当您声明正常 std::string 时,此输出有效。有了这个说明;当你有:

std::string hello2[2] = {"hello", "world"}; std::cout<<hello2[0][2]<<hello2[1][3];

这个输出应该是:ll

在所有这些信息都为真的情况下,一维 std::string 数组会被视为矩阵吗?

矩阵是数字或其他数学对象的矩形数组,其中定义了加法和乘法等运算 ([https://en.wikipedia.org/wiki/Matrix_(mathematics]))。当涉及一维 std::string 数组时,它们总是 矩形 的 属性 不成立。例如,您可以具有以下内容:

std::string strNames[] = { "David", "Bob", "Yana" }; 

对于上述数组,值strNames[1][3]没有明确定义。在矩阵的情况下,如果第一列有 5 个值,那么所有其他行也应该有 5 列,一维 std::string 数组可能是也可能不是这种情况。因此,你不能说一维 std::string 数组也是矩阵。