Subject: [Boost-bugs] [Boost C++ Libraries] #5164: STL string::find
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-02-06 15:51:25
#5164: STL string::find
------------------------------------+---------------------------------------
Reporter: mailsystems@⦠| Owner:
Type: Bugs | Status: new
Milestone: To Be Determined | Component: None
Version: | Severity: Problem
Keywords: |
------------------------------------+---------------------------------------
string::find bug
Return Value
The position of the first occurrence in the string of the searched
content.
If the content is not found, the member value '''npos''' is returned.
string::npos - return max allowed string size
Example - return all founded position in string
int main()
{
string str = "aaaaaaaaaaaaaaaaa"; // base string
string search_str = ""; // epmty string for search
size_t found_pos; // found position
size_t start_pos = 0; // start position
while((found_pos = str.find(search_str, start_pos) != string::npos)
{
cout << "Found position: " << found_pos << " Start position: "
<< start_pos << endl;
start_pos = found_pos + search_str.size(); // search next
}
}
If '''string::find''' function first argument is uninitialized variable,
then function '''string::find''' return '''0''' (zero) not
'''string::npos''' and when while is loop still '''found_pos ==
string::npos'''.
Same affect if '''string search_str;'''
Thanks
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/5164> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:05 UTC