2010-06-21 19 views
1

以下應用程序在第一行中給我一個訪問衝突,那是什麼?錯誤在一行Xerces程序

// 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; 
} 
+0

就像一個健全的檢查,如果你刪除了對XMLString :: transcode()的調用,它是否仍然崩潰? – WildCrustacean 2010-06-21 15:56:07

回答

1

程序中的一個明顯錯誤是,您在使用它之前沒有初始化xerces-c。

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

您必須進行任何其他調用的Xerces-C之前調用XMLPlatformUtils::Initialize()

+0

非常感謝查爾斯,也許你會友善地幫助我進一步查詢,我用我的新問題更新了我的原始問題。謝謝 – Gungho 2010-06-21 16:44:36

+0

@Tim:正如你已經接受了這個問題的答案,你的新問題與原來的措辭有實質性的不同,將它作爲一個新問題會更有意義。 – 2010-06-21 17:22:54

+0

我在這裏問了一個新問題http://stackoverflow.com/questions/3091484/exception-in-two-line-xerces-program – Gungho 2010-06-22 08:34:00