My program have a problem, the data is from a note pad ..... it says initializer fails to determine size of str; help thanks i need answer asap :D GODBLESS
The error is probably related to this. When you declare a variable of type char[], it has to be constant or already defined -- e.g.:
char str[] = "Here is a string!";
This is because the compiler needs to know how large it is in advance. When you are trying to read in a string of unknown length, like something from a file, I would recommend using char*. Or, even easier, I'd just do something like this:
1 2 3 4 5 6 7 8
cout<<on<<endl;
char delims[] = ",";
char *result = NULL;
result = strtok( on.c_str(), delims );
while( result != NULL )
{
cout<<result<<endl;
result = strtok( NULL, delims );
so what should be the datatype of my "on" variable?
It should a string, as you already have it.
1 2
string on;
getline(read,on);
As shown above by Moeljbcp, the strtok function requires a plain C-string, which can be obtained by using on.c_str().
It can be a little confusing, as the program is making use of two different types of string, the ordinary c-string (which is just an array of characters terminated by a null), and also the more advanced C++ string.