C++ C++;在文本之前查找字符串
给定的代码在字符串中的一个特定点之后获取所有文本,效果非常好C++ C++;在文本之前查找字符串,c++,string,C++,String,给定的代码在字符串中的一个特定点之后获取所有文本,效果非常好 if(text.find("what ") != std::string::npos) { foundtext = text.substr(text.find("what ") + 5); cout << foundtext << endl; } if(text.find(“what”)!=std::string::npos) {
if(text.find("what ") != std::string::npos)
{
foundtext = text.substr(text.find("what ") + 5);
cout << foundtext << endl;
}
if(text.find(“what”)!=std::string::npos)
{
foundtext=text.substr(text.find(“what”)+5);
cout您需要为substr()
提供两个参数:
第一个(0
)是起始位置,第二个是长度。text.substring(0,positionof(what))可能吗?如果答案解决了问题,你应该接受
foundtext = text.substr(0, text.find("what "));