Ofstream не принимает строку или символ * для печати в файл - PullRequest
0 голосов
/ 05 мая 2019

Я получил эту функцию в классе, где я вызываю функцию в существующей части класса, давая файл, в который я хочу поместить данные, но всегда выдает эту ошибку: C2676 двоичный '<<': 'std :: ofstream' не определяет этот оператор или преобразование в тип, приемлемый для предопределенного оператора </p>

#include <iostream>
#include <string>

template <class T>
class Node
{
    T data;
    Node* right;
    Node* left;
    bool exist;
public:
void print2File(std::ofstream &OutputFile)
    {
        if (this == nullptr)
        {
            return;
        }
        OutputFile << data;
        if (left != nullptr || right != nullptr)
        {
            std::string str1 = "( ";
            std::string str2 = " , ";
            std::string str3 = " )";
            OutputFile << str1;
            if (left != nullptr)
                left->print2File(OutputFile);
            OutputFile << str2;
            if (right != nullptr)
                right->print2File(OutputFile);
            OutputFile << str3;
        }
    }
}
...