gpt4 book ai didi

c++ - DataContractSerialize 错误

转载 作者:行者123 更新时间:2023-11-28 08:09:25 25 4
gpt4 key购买 nike

这里有一些说明问题的测试代码:

编译配置:

公共(public)语言运行时支持:/clr

C++ 语言

错误信息:

错误 4 错误 C2065:“DataContractSerializer”:未声明的标识符 C:...\SerializationTest.cpp 21 1 SerializationTest

代码:

// SerializationTest.cpp : main project file.

#include "stdafx.h"

using namespace System::Collections::Generic;
using namespace System;

using namespace System::IO;
using namespace System::Xml;
using namespace System::Runtime::Serialization;

int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");

Dictionary<System::String^, System::Double>^ teste = gcnew Dictionary<System::String^, System::Double>();
teste->Add("Teste1",2);
teste->Add("Teste2",4);

DataContractSerializer^ serializer = gcnew DataContractSerializer(teste->GetType());
StringWriter^ writer = gcnew StringWriter();
XmlTextWriter^ stm = gcnew XmlTextWriter(writer);
serializer->WriteObject(stm, teste);

Console::WriteLine(writer->ToString());

return 0;
}

最佳答案

这听起来就像您缺少对 System.Runtime.Serialization.dll 的引用(除了 using 指令之外,它是必需的):

#using <System.Runtime.Serialization.dll>

关于c++ - DataContractSerialize 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9499470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com