Stackoverflow users!
I am using Borland C++ Builder 6 for creating my program. Yes, I know that it is outdated for last two millon years, however, I have to use this IDE. I have a String which I need to split. So I use the following method:
void Orders::split(TStringList* lout, char* str, const char* separator) {
for(char* tok = strtok(str, separator); tok!=NULL; tok = strtok(NULL, separator))
lout->Add(tok);
}
Also, I have a separator defined as a preprocessor constant:
#define SEPARATOR ':'
Then I call the split method
split(ords, input.c_str(), SEPARATOR);
And I get the following error:
[C++ Error] File3.cpp(47): E2034 Cannot convert ‘int’ to ‘const char *’
On the line, where I call the split method. Casting to const char* leads to the same result. Is there a bug in the IDE or am I just too dumb to see my own error in code?
Thanks in advance!
strtokis looking for aconst char*as delimiters. Try defining it like this instead:This is because you can specify a set of delimiters, so that
strtokstops if any of those characters is found.