I guess I should use a C++ helper to get a constant StringAttr instance. But I could not find a constructor of StringAttr with std::string as input. How should I do?
If you need constant attributes in patterns you can use instances of ConstantAttr as operands in the result pattern. For string-like atrtibutes in particular there is ConstantStrAttr which takes care of the quoting.
For the example you posted this would be: