Hi,

I'm trying to make a program that to start with, splits a string into smaller parts if there's spaces in the string. My only problem is that can make it split a string declared from the beginning of the program, but now make a user-defined one. And when afterwards how do I get it into some kind of array, so that I can work with them?

Here's my work so far:

Code:
//includes
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
 
//namespace
using namespace std;
 
//- Function name: Tokenize 
//--------------------------
 
void Tokenize(const string& str, vector<string>& tokens, const string& delimiters = " ") 
{
//Skip delimiters at beginning.
string::size_type lastPos = str.find_first_not_of(delimiters, 0);
//Find first "non-delimiter".
string::size_type pos	 = str.find_first_of(delimiters, lastPos);
//Cut the string.
while(string::npos != pos || string::npos != lastPos)
{
//Found a token, add it to the vector.
tokens.push_back(str.substr(lastPos, pos-lastPos));
//Skip delimiters. Note the "not_of".
lastPos = str.find_first_not_of(delimiters, pos);
//Find next "non-delimiter".
pos = str.find_first_of(delimiters, lastPos);
}
}
 
int main() 
{
vector<string> tokens;
 
string str("+x^2 +y^2 -4x +9y");
 
Tokenize(str, tokens);
 
copy(tokens.begin(), tokens.end(), ostream_iterator<string>(cout, "\n"));
}