2013-05-05 131 views
-1

我得到以下链接错误入门链接错误,运行我的C在VS2008 ++代码中,我已经使用C++ STL同时:同时使用STL容器

error LNK2001: unresolved external symbol "public: static class std::_Tree<class 
std::::_Tmap_traits<class std::basic_string<char,struct std::char_traits<char>, 
class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char> 
,class std::allocator<char> >,struct std::less<class std::basic_string<char,struct 
std::char_traits<char>,class std::allocator<char> > >,class std::allocator<struct 
std::pair<class std::basic_string<char,struct std::char_traits<char>,class std:: 
allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>, 
class std::allocator<char> > > >,0> >::iterator parser::parsedDataIterator" 
([email protected]@@[email protected][email protected][email protected][email protected]?$ 
[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected][email protected][email protected]?$char_traits 
@[email protected]@@[email protected]@[email protected]@[email protected]@@[email protected][email protected][email protected][email protected]?$char 
[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@[email protected][email protected]@[email protected]@@[email protected]@A) parser.obj 

我没有与代码相关联的所有库,不知道是否有任何需要。

下面是成功编译代码:

//Including header file that just contains the class declaration 
#include "parser.h" 

//Static variable definitions... 
int parser::lang = -1; 
std::string parser::fullString; 
std::map<std::string, std::string> parser::parsedData; 
std::map<std::string, std::string>::iterator parsedDataIterator; 
std::stack<char> parser::symbolStack; 

//The parsing function used to parse XML content.. 
bool parser::XMLParser(std::string arg_String) 
{ 
    //Create empty strings... 
    std::string tagText; 
    std::string emptyString = ""; 
    //Maintain count for string length 
    int count = 0; 

    //Loop over whole string... 
    for(unsigned int i=0 ; i<arg_String.length() ; i++) 
    { 
     //ignore white string when not reading internal tag text content... 
     cout<<"Value of i : "<<i<<" ... Value of str.char is :"<<arg_String[i]<<endl; 
     if(arg_String[i] == ' ' && count==0) 
      continue; 

     if(arg_String[i] == '<'){ 
      symbolStack.push(arg_String[i]); 
      tagText.clear(); 
     } 
     else if(arg_String[i] == '>'){ 
      symbolStack.pop(); 
      parsedData[tagText] = ""; 
     } 
     else{ 
      tagText.push_back(arg_String[i]); 
      count++; 
     } 


    } 
    if(symbolStack.empty()) 
    { 
     cout<<"XML parsing was successful :"<<endl; 
     return true; 
    } 
} 

bool parser::populateAndReturn(std::string arg_String) 
{ 
    bool status = false; 
    status = XMLParser(arg_String); 
    return status; 

} 

int main(int argc, char *argv[]) 
{ 
    std::string inputString = "<html>"; 
    if(parser::populateAndReturn(inputString)) 
    { 
     for(parser::parsedDataIterator = parser::parsedData.begin(); parser::parsedDataIterator != parser::parsedData.end(); ++parser::parsedDataIterator) 
     cout << "Key: " << (*parser::parsedDataIterator).first << " Value: " << (*parser::parsedDataIterator).second; 
    } 
    else 
     cout<<"\nError encountered while parsing"; 
    system("pause"); 
} 

守则 “parser.h”:

#pragma once 

#include<iostream> 
#include<fstream> 
#include <map> 
#include <stack> 
#include <string> 

using namespace std; 

class parser 
{ 
    static std::string fullString; 
     //Declaring a map that will associate the tag with the container text. 
    static std::stack<char> symbolStack; 

public: 
    static std::map<std::string, std::string> parsedData; 
    static std::map<std::string, std::string>::iterator parsedDataIterator; 

    parser(){ 
    } 

    static int lang; 

    static enum format{ 
     XML, 
     JSON, 
     ZZZ = -1 
    }; 

    static bool populateAndReturn(std::string arg_String); 
    static bool XMLParser(std::string arg_String); 
}; 
+0

http://sscce.org请。 – chris 2013-05-05 06:48:56

+0

@chris为了清晰起见添加了代码......谢谢 – cbinder 2013-05-05 07:05:01

+0

'parser.h'。 – 2013-05-05 07:26:13

回答

1

您从解析器:: parsedDataIterator不放过类名。

在你的static成员,变化的定义:

std::map<std::string, std::string>::iterator parsedDataIterator; 

到:

std::map<std::string, std::string>::iterator parser::parsedDataIterator; 
              //^^^^^^^^ 
+0

中包含了非常感谢...解决了问题:) – cbinder 2013-05-05 07:56:37