The functions you showed are wrong. Member function find
of class std::string
does not return a bool value. It returns an object of type std::string::size_type
So for example the first function could look the following way
int formatStringNumerator( const string &rational )
{
string tmp( rational, 0, rational.find("/") );
tmp.erase( 0, tmp.find_first_not_of( "(" ) );
return ( tmp.empty() ? 0 : std::stoi( tmp ) );
}
Here is an example of using the function
#include <iostream>
#include <string>
using namespace std;
int formatStringNumerator( const string &rational )
{
string tmp( rational, 0, rational.find("/") );
tmp.erase( 0, tmp.find_first_not_of( "(" ) );
return ( tmp.empty() ? 0 : std::stoi( tmp ) );
}
int main()
{
std::string s( "((((12/15" );
std::cout << formatStringNumerator( s ) << std::endl;
std::string t( "((((12" );
std::cout << formatStringNumerator( t ) << std::endl;
std::string u( "((((" );
std::cout << formatStringNumerator( u ) << std::endl;
return 0;
}
The output is
12
12
0