如何查找子字符串的位置并从那里打印它
how to find location of a substring and print it from there
到目前为止,我有这个
if(tempString.find(mString) != string::npos) //if found word
{
cout<<endl<<tempString<<endl; //this prints the entire line
}
例如,如果 tempString 是"For he I not know",而 mString 是 "I do",它将打印 "I not know"
我知道 tempString.find(mString) 返回子字符串的位置。如何使用它从子字符串开始打印
use std::string::substr:
size_t pos = tempString.find(mString);
if (pos != string::npos)
{
std::string to_print = tempString.substr(pos);
cout << to_print;
}
相关文章:
- C++需要帮助从用户那里获得一个整数,并确保它在另外两个整数之间
- 如何从用户那里获取输入并将其存储在向量中?
- 如何使此递归函数从给定的起始位置返回最小的整数?
- 从用户那里获取数组大小的值
- C++ deque 消费者总是从生产者那里得到空队列
- C++ 从具有开始位置和结束位置的列表中删除
- 代码在执行之前终止,并且没有从用户那里获取输入
- 我无法在某个点(从用户那里)获得输入,即使没有错误弹出编译
- 将顶点位置从顶点传递到片段着色器 - 仅在使用 Nsight 进行调试时有效
- 从用户那里获得无限量的输入,而不是打印最大的3个,而不使用数组
- 如何从几乎排序的链表中分离放错位置的元素?
- C++将可变数量的位置从给定数组传递到函数
- 根据数字在 c++ 中作为矩阵的位置从文件中读取数字
- C 如何进行计数循环,该循环确定两个输入数字中的哪个是最低的,并且从那里计数
- 如何查找子字符串的位置并从那里打印它
- 通过在每个位置从特定位置的单词池中选择单词,有效地生成所有序列
- 如何连续将鼠标的位置从对话框中移开?(MFC)
- 如何将鼠标位置从SFML转换为OpenGL坐标
- 按值而不是按位置从方形向量中移除元素
- 从x那里得到了意想不到的答案?y: z表达式