-1

I have taken many looks, but I have not been able to find a working snippet which I would understand at my current learning level. What I'm aiming to do is again:

  • Take input:string input = "Eggs and Spam";

  • Tokenize it, and then put the tokens (together) into a list: Which I see as this: inputlist = ["Eggs", "and", "Spam"];

First, I may like to know how to (hopefully briefly) declare a list, and do the above by appending the list.

In terms of C++, I'm also curious how I could do so when using only the default libraries, as I am having trouble handling library files at the moment.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Air Conditioner
  • 123
  • 1
  • 2
  • 6
  • 1
    any specific language you want to do this in? or are you more generally asking about the abstract procedure that you would need to follow? – Bob Fincheimer May 28 '14 at 22:50
  • I edited the question to include the specific language, but I would love an explanation on how the vector arrays work. – Air Conditioner May 30 '14 at 01:46

1 Answers1

0

The easiest way is using Boost's Strings Algorithm library - http://www.boost.org/doc/libs/1_55_0/doc/html/string_algo/usage.html#idp206847064

Then it's as easy as:

vector<string> parts;
split( parts, "Eggs and Spam", is_any_of(" "), token_compress_on )
Yeraze
  • 3,269
  • 4
  • 28
  • 42
  • 1
    He explicitly said no 3rd party libraries, though otherwise you're right. – Lightness Races in Orbit May 30 '14 at 00:43
  • Now that I see that snippet once again, I can't help but see to setting up the library when I get the time. However, my one concern is this: If I compile a program referring to a non-generic library, would the program be able to work without including the boost library files with it? – Air Conditioner May 30 '14 at 01:43
  • You could compile & link it statically, which would include the 3rd party libraries inside your resulting binary, simplifying distribution. – Yeraze May 30 '14 at 02:32
  • Neat! However, when I attempt to **#include** the library, using the path posted on the boost website, the GNU GCC compiler I use always turns out errors. How could I fix that? (In the case this matters, I use the Code::Blocks IDE) – Air Conditioner May 30 '14 at 14:26
  • Without details on the errors I can't help.. Make sure you add the include path to the compile line ( `-I` ) and the library path and name to the link line ( `-Ldirectory -lboost` ) – Yeraze May 30 '14 at 15:53