在c++中写出以下问题的解决方案:给定二进制树的根,从二进制树中构建一个包含括号和整数的字符串,并返回它. 省略所有没有影响字符串和原始二进制树之间的对对映射关系的空括号对.
Here is a C++ function that solves the problem:

```
string tree2str(TreeNode* root) {
    if (root == nullptr) {
        return "";
    } else if (root->left == nullptr && root->right == nullptr) {
        return to_string(root->val);
    } else if (root->left != nullptr && root->right == nullptr) {
        return to_string(root->val) + "(" + tree2str(root->left) + ")";
    } else {
        return to_string(root->val) + "(" + tree2str(root->left) + ")(" + tree2str(root->right) + ")";
    }
}
```

This function takes the root of the binary tree as input and returns the string representation of the tree using the preorder traversal method. 

The function first checks if the root is a leaf node, meaning it has no left or right children. If it is, the function returns the value of the node as a string.

If the root has a left child but no right child, the function recursively calls itself on the left child and wraps it in parentheses. The value of the root node is also included.

If the root node has both left and right children, the function recursively calls itself on both children and wraps them in separate sets of parentheses. The value of the root node is also included.

Finally, if the root is null, an empty string is returned.