c++ - 遍历字符串数组中的字符?

标签 c++ arrays string

在 C++ 中,我有一个字符串数组,比如说:

string lines[3]

lines[0] = 'abcdefg'
lines[1] = 'hijklmn'
lines[2] = 'opqrstu'

有没有办法循环遍历每个索引中的字符以及遍历索引?像 lines[i[j]]?

最佳答案

试试这段代码:

std::string lines[3];

lines[0] = "abcdefg";
lines[1] = "hijklmn";
lines[2] = "opqrstu";

for (int i=0; i < lines.length(); ++i) {
    for (int j=0; j < lines[i].length(); ++j) {
        std::cout << lines[i][j];
    }
}

关于c++ - 遍历字符串数组中的字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30905681/

相关文章:

c++ - 使用 boost 库编写多线程程序时出错

arrays - 如何在Powershell中使用2D阵列?

arrays - MongoDB 更新数组元素

不使用 sprintf() 将 float 转换为字符串

c++ - 复制构造函数应该复制 *string 值

c++ - Visual C++ 表达式必须具有常量值

c++ - 初始化多个指针时出现运行时错误

c++ - .c_str() 怪异?数据变化无缘无故?

c++ - 针对 64 位错误编译 GINA.dll

javascript - 从 Controller Angular 传递数组