知道循环中std :: string的结束

SH.*_*x90 1 c++ string std c++11

我想知道如何知道循环中std :: string的结束?

例如:

while(string.eof()) {}
Run Code Online (Sandbox Code Playgroud)

记住它与std :: string一起使用

谢谢你们.

jua*_*nza 8

您可以像循环遍历标准库容器一样遍历字符串:

for (auto c : s)
{
  // do something with c
}
Run Code Online (Sandbox Code Playgroud)

要么

for (auto it = s.begin(), end = s.end(); it != end; ++it)
{
  // do something with it
}
Run Code Online (Sandbox Code Playgroud)

s字符串在哪里.