C++ 搜索std::字符串

C++ 搜索std::字符串,c++,string,C++,String,我希望搜索字符串,例如: std::string str = "_Data_End__Begin_Data_End"; |_________| |_____________| data data section1 section2 如果我在str中搜索“Begin”,如果在“数据部分1中找不到它,我希望确保它确实在“数据部分2”中查找 如果我知道“dat

我希望搜索字符串,例如:

std::string str = "_Data_End__Begin_Data_End";
                  |_________| |_____________|
                      data        data
                    section1     section2
如果我在
str
中搜索“Begin”,如果在“
数据部分1
中找不到它,我希望确保它确实在“
数据部分2
”中查找

如果我知道“
data section 1
”的长度,是否可能?

std::string::find()
有一个可选参数来指示从何处开始搜索:

str.find("Begin", length_of_data_section1);

下面的代码在字符串中搜索“Begin”

std::string::size_type loc=str.find(“Begin”);
if(loc!=std::string::npos)
{

std::cout您的确切意思是什么?是什么界定了这两个数据部分?如果在“数据部分1”中找不到字符串,则标准查找将在“数据部分2”中查找,因为它将扫描整个字符串。但是在数据部分1中搜索它呢?
std::string::size_type loc = str.find("Begin");
if(loc != std::string::npos)
{
    std::cout << "found \"Begin\" at position " << loc << std::endl;
}