You have 2 parcels to Cainiao StationPlease with 10-1-3125 1-5-4453 pickthem up before 1700如何只读取with和pick之间的字符 c++
要实现只读取"with"和"pick"之间的字符,可以使用C++中的字符串处理函数。下面是一个示例代码:
#include <iostream>
#include <string>
int main() {
std::string input = "Please with 10-1-3125, 1-5-4453 pick them up before 17:00.";
// 找到"with"和"pick"的位置
size_t startPos = input.find("with") + 4; // 4是"with"的长度
size_t endPos = input.find("pick");
// 提取"with"和"pick"之间的子字符串
std::string result = input.substr(startPos, endPos - startPos);
// 输出结果
std::cout << result << std::endl;
return 0;
}
输出结果为:
10-1-3125, 1-5-4453
这段代码使用find函数找到"with"和"pick"的位置,然后使用substr函数提取两者之间的子字符串
原文地址: https://www.cveoy.top/t/topic/hYIa 著作权归作者所有。请勿转载和采集!