我有一个字符串,我需要在其中获取每个字符并进行一些检查:
std::string key = "test"
int i = 0;
while (key.at(i))
{
// do some checking
i++;
}
这里的问题是,索引 i
最终会超出范围,因此系统会崩溃。我该如何解决这个问题?
最佳答案
std::string key = "test"
for(int i = 0; i < key.length(); i++)
{
//do some checking
}
关于c++ - 如何遍历字符串中的每个字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11303391/