c++ - 如何在 C++ 文件中写入结构类型的指针

标签 c++

这是一个 C++ 代码。我想写一个指向文件中结构的指针。 当我尝试这样做时,它会产生错误。我做的是 >> obj1[0].contentAdress;在主要。

struct node3{
    node3(){
        nextContent = NULL;
        for (int i = 0; i<1020; i++)
            content[i] = '\0';
    }
    char content[1020];
    node3* nextContent;
};

//-------------------------------------------- ----------------------------------------------

struct node1{
    node1(){
        for (int i = 0; i<496; i++)
            fileName[i] = '\0';
    }

    char fileName[496];
    node3* contentAdress;
};

//-------------------------------------------- ----------------------------------------------

int main(){

    node1 obj1[2097];
    node3 obj3[8192];


        ifstream is("file.txt");
//I want the obj1[0].content Address to be written in file. For that I did:
        **is >> obj1[0].contentAdress;** *THIS GENERATES AN ERROR*

        return 0;
    }

错误:

error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'node3 *' (or there is no acceptable conversion)

最佳答案

将其转换为 uint32(或 64 位系统上的 uint64)。但可能这不是你想要的,因为很少有情况需要将指针写入文件。

关于c++ - 如何在 C++ 文件中写入结构类型的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20168737/

相关文章:

c++ scanf导致SIGSEGV

c++ - Q. 速度在 "R with indicator"和 "c++ with for"之间

C++ 指向成员函数的指针、声明

c++ - 生成一个随机的unicode字符串

c++ - 如何在 std::vector<strings> 中查找重复项并返回按字母顺序排序的 std::list,结果列表中没有重复项

c++ - 在 QHBoxLayout 中将小部件添加到屏幕外以便稍后显示

c++ - 从另一个线程调用函数

c++ - accumulate 和 ostringstream 编译错误

C++:将类作为参数传递给其他类的方法

c++ - "Email"读者 - 奇怪的迭代器问题