在 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/