这是一个 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/