-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);
};
http://sscce.org請。 – chris 2013-05-05 06:48:56
@chris爲了清晰起見添加了代碼......謝謝 – cbinder 2013-05-05 07:05:01
'parser.h'。 – 2013-05-05 07:26:13