| mrghaia (10) | |||
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 | |||
|
Last edited on
|
|||
| Moeljbcp (85) | |||
char str[] = on;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:
Best of luck and I hope this helps. | |||
|
|
|||
| mrghaia (10) | |
|
hmm sir so what should be the datatype of my "on" variable?? | |
|
|
|
| mrghaia (10) | |
|
very sorry for being slow I'm a newbie ^_^ i hope somebody there has a heart to help me.. if possible please edit my source code ty so much appreciated I will have my exam this november I need to pass thank you so muck Mr. Moeljbcp ^^ | |
|
Last edited on
|
|
| Riper97 (16) | |
|
Here ;) This will Read And Print Everything from ur text file :) string line; ifstream myfile ("example.txt"); while ( myfile.good() ) { getline (myfile,line); cout << line << endl; } myfile.close(); Also i am working on a project and tell me if u wanna team up :) | |
|
Last edited on
|
|
| mrghaia (10) | |
|
lets team up bro :D ur targeting for NC 4 exam?? also? | |
|
Last edited on
|
|
| mrghaia (10) | |
| anyone can help me about this program? | |
|
|
|
| Chervil (812) | ||||
It should a string, as you already have it.
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. | ||||
|
|
||||
| mrghaia (10) | |
| You solved!! Thanks For The Help Guys.. :D | |
|
|
|