1

次のアプリケーションでは、最初の行でアクセス違反が発生します。これは何ですか?

// test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <xercesc/util/XMLString.hpp>

using namespace xercesc;

int main()
{

    XMLCh* path= XMLString::transcode("test.xml"); 

    return 0;
}

[編集] 次のコードでは XMLFormatTarget 行で例外が発生しますが、文字列を "C:/test.xml" から "test.xml" に変更すると問題なく動作します。

// test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/framework/LocalFileFormatTarget.hpp>

using namespace xercesc;

int main()
{
    XMLPlatformUtils::Initialize();

    XMLFormatTarget *formatTarget = new LocalFileFormatTarget("C:/test.xml"); 

    return 0;
}
4

1 に答える 1

1

プログラムの明らかなエラーは、使用する前に xerces-c を初期化していないことです。

http://xerces.apache.org/xerces-c/program-2.html

XMLPlatformUtils::Initialize()xerces-c を呼び出す前に呼び出す必要があります。

于 2010-06-21T16:04:56.787 に答える