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.
Scrivi una soluzione per il seguente problema in c++: data la radice di un albero binario, costruisci una stringa composta da parentesi e numeri interi da un albero binario con il modo di attraversamento del preordine e restituiscila. Omettere tutte le coppie di parentesi vuote che non influiscono sulla relazione di mappatura uno a uno tra la stringa e l'albero binario originale.