Alex Rivera | Logout

How to use string::find to find either "+" or "-" in one operation

Asked 2012-12-04T10:02:44.287
8

I want to find the location of + or - in a complex number , e.g.

x + y*i 

x - y*i

Usually , I will do this :

int found = str.find("+");
if (found != string::npos)
    cout << "'+' also found at: " << found << endl;


found = str.find("-");
if (found != string::npos)
    cout << "'-' also found at: " << found << endl;

How can I give find multiple options to find in a single run ?

Edit
Report

1 Answer

1

Use find_first_of().

Here's a reference for the std::string methods. http://www.cplusplus.com/reference/string/string

answered 2012-12-04T10:09:08.740

Your Answer