📌  相关文章
📜  如何在 C++ 代码示例中获取字符串的一部分

📅  最后修改于: 2022-03-11 14:44:46.817000             🧑  作者: Mango

代码示例1
// string::substr
#include 
#include 
using namespace std;

int main ()
{
  string str="We think in generalities, but we live in details.";
                             // quoting Alfred N. Whitehead
  string str2, str3;
  size_t pos;

  str2 = str.substr (12,12); // "generalities"

  pos = str.find("live");    // position of "live" in str
  str3 = str.substr (pos);   // get from "live" to the end

  cout << str2 << ' ' << str3 << endl;

  return 0;
}