I have an error : 'split' was not declared in this code
I don't know why it say that because I don't think I have a declaration problem
Here's my code
std::vector<std::string> x = split("43 24 35 82", ' ');
int total = 0;
int main() {
// then we loop over the elements
for(size_t i = 0; i < x.size(); ++i) {
// convert the string to an integer
int n = atoi(x[i].c_str());
total = total + n;
}
It says that because split is not declared in this scope. Your code just confirms that. You use function split(), but never define or declare it. I do not see any included headers here - maybe that's what you forgot to add at the top of the code.
Remember - split must be declared BEFORE it is used, not at the bottom of .cpp file.
Remember - split must be declared BEFORE it is used, not at the bottom of .cpp file.
just to expand... it must be declared before using it, howeber you can prototype it and define it (almost) wherever you please). and he was just showing us his code. it would say error namespace std not in this scope before it would get to split. which means he must have declared iostream, vector, and string. he probably meant to use string::split
Did you write the function split()? I don't think that it is one of the standard ones. If you wrote it, the fastest thing to do would be to copy and paste it just above the main function. If you are not the author - where do you expect to find the function? Is it in any header file you got? Give us more details about this function, and we just might figure it out :)/