Unresolved External Symbol Error

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2006
Posts: 3
Reputation: delphi_uk is an unknown quantity at this point 
Solved Threads: 0
delphi_uk delphi_uk is offline Offline
Newbie Poster

Unresolved External Symbol Error

 
0
  #1
Mar 15th, 2007
Hello to you all,

I am having problems with some code that I am working on for a text parsing system from an external *.txt file. The problem seems to stem from the Tokenize function, as I get a:

"LNK2019 error: unresolved external symbol "void __cdecl Tokenize(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<class std::basic_string<char,struct std::char_traits<char>, class std::allocator<char> >, class std::allocator<class std::basic_string<char, struct std::char_traits<char>,class std::allocator<char> > > > &)"

  1. // stringtest.cpp
  2.  
  3. #include <string>
  4. #include <algorithm>
  5. #include <vector>
  6. #include <iostream>
  7. #include <fstream>
  8.  
  9. using namespace std;
  10.  
  11. void Tokenize(const string& str, vector<string>& tokens);
  12.  
  13. int main()
  14. {
  15. vector<string> tokens;
  16.  
  17. char _string[256];
  18. char inputChar[256];
  19. string inputString;
  20. ifstream input;
  21.  
  22. cout << "Enter name of an existing file: ";
  23. cin.get( _string, 256 );
  24.  
  25. input.open( _string );
  26.  
  27. input.getline( inputChar, 256 );
  28. cout << inputChar << endl;
  29. inputString = inputChar;
  30. cout << inputString << endl << endl;
  31.  
  32. Tokenize( inputString, token );
  33. copy( tokens.begin(), tokens.end(), ostream_iterator<string>(cout, ", "));
  34.  
  35. return 0;
  36. }
  37.  
  38. void Tokenize( const string& str, vector<string>& tokens, const string& delimiters = "|")
  39. {
  40. // Tokenize taken from [URL]http://www.hispafuentes.com/[/URL]
  41. // Skip delimiters at the beginning
  42. string::size_type lastPos = str.find_first_not_of( delimeters, 0 );
  43. // Find first "non-delimiter".
  44. string::size_type pos = str.find_first_of( delimiters, lastPos );
  45.  
  46. while (string::npos != pos || string::npos != lastPos)
  47. {
  48. // Found a token add it to the vector
  49. tokens.push_back( str.substr(lastPos, pos - lastPos));
  50. // Skip delimiters. Note the "not_of"
  51. lastPos = str.find_first_not_of( delimiters, pos);
  52. // Find next "non-delimiter"
  53. pos = str.find_first_of( delimiters, lastPos );
  54. }
  55. }

Thank you very much in advance,

Delphi
Last edited by delphi_uk; Mar 15th, 2007 at 7:50 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,050
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: Unresolved External Symbol Error

 
0
  #2
Mar 15th, 2007
How in the world did you get it to compile? For one thing, you'll need to #include <iterator> if you intend on using ostream_iterator.

  1. int main()
  2. {
  3. vector<string> tokens;
  4.  
  5. char _string[256];
  6. char inputChar[256];
  7. string inputString;
  8. ifstream input;
  9.  
  10. cout << "Enter name of an existing file: ";
  11. cin.get( _string, 256 );
  12.  
  13. input.open( _string );
  14.  
  15. input.getline( inputChar, 256 );
  16. cout << inputChar << endl;
  17. inputString = inputChar;
  18. cout << inputString << endl << endl;
  19.  
  20. Tokenize( inputString, token ); // add an 's' to 'token'

  1. void Tokenize( const string& str, vector<string>& tokens, const string& delimiters = "|")
  2. {
  3. // Tokenize taken from [url]http://www.hispafuentes.com/[/url]
  4. // Skip delimiters at the beginning
  5. string::size_type lastPos = str.find_first_not_of( delimeters, 0 ); // you're spelling 'delimiters' wrong
"Technological progress is like an axe in the hands of a pathological criminal."
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 3
Reputation: delphi_uk is an unknown quantity at this point 
Solved Threads: 0
delphi_uk delphi_uk is offline Offline
Newbie Poster

Re: Unresolved External Symbol Error

 
0
  #3
Mar 15th, 2007
Originally Posted by joeprogrammer View Post
How in the world did you get it to compile? For one thing, you'll need to #include <iterator> if you intend on using ostream_iterator.
I didnt manage to get it compile thats why I was getting the error. Thanks for the advice on the iterator, the site that I took the code snippet from did not have that header in the sample code.

Originally Posted by joeprogrammer View Post
  1. Tokenize( inputString, token ); // add an 's' to 'token'
My appologies on the spelling mistake, that was human error as I copied the code from my laptop to the desktop, in the original program this was correct.

Originally Posted by joeprogrammer View Post
  1. void Tokenize( const string& str, vector<string>& tokens, const string& delimiters = "|")
  2. {
  3. // Tokenize taken from [url]http://www.hispafuentes.com/[/url]
  4. // Skip delimiters at the beginning
  5. string::size_type lastPos = str.find_first_not_of( delimeters, 0 ); // you're spelling 'delimiters' wrong
Again this is due to inaccuracies in copying the program.

However non of these issues that were brought up solved the issue of the LNK2019 error.

Also thank you very much for the fast response, I have lurked on these forums and used some solutions for quite some time, however this is the first time I have needed to ask a question.

Delphi
Last edited by delphi_uk; Mar 15th, 2007 at 8:15 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,050
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: Unresolved External Symbol Error

 
0
  #4
Mar 15th, 2007
Another note: you should place your default parameter thingy in the function prototype instead of the actual function implementation. This is likely what's causing the linker errors.

[edit]

The actual reason for the linker errors is this:
  1. void Tokenize(const string& str, vector<string>& tokens);
You never included the third parameter, delimiters. No wonder the linker choked up.
Last edited by John A; Mar 15th, 2007 at 8:32 pm.
"Technological progress is like an axe in the hands of a pathological criminal."
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 3
Reputation: delphi_uk is an unknown quantity at this point 
Solved Threads: 0
delphi_uk delphi_uk is offline Offline
Newbie Poster

Re: Unresolved External Symbol Error

 
0
  #5
Mar 15th, 2007
Brilliant! Thank you so much, I really shouldn't code when I am tired.

Thank you again for your help!

Delphi
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC