Problem with output

Hey guys, i am having problem with displaying my text. my text file is displayed in such a way and is called test.......

Sam Worthington ... Jake SullyasZoe Saldana ... NeytiriasSigourney Weaver ... Dr. Grace AugustineasStephen Lang ... Colonel Miles QuaritchasJoel Moore ... Norm Spellman (as Joel David Moore)asGiovanni Ribisi ... Parker SelfridgeasMichelle Rodriguez ... Trudy ChaconasLaz Alonso ... Tsu'teyasWes Studi ... EytukanasCCH Pounder ... MoatasDileep Rao ... Dr. Max PatelasMatt Gerald ... Corporal Lyle WainfleetasSean Anthony Moran ... Private FikeasJason Whyte ... Cryo Vault Med TechasScott Lawrence ... Venture Star Crew Chiefmore
What i am trying to do is for the program to read "as" and then from there start a new line... thus the expected output is...


1
2
3
4
5
6
7

Sam Worthington ... Jake Sully
Zoe Saldana ... Neytiri
Sigourney Weaver ... Dr. Grace Augustine
Stephen Lang ... Colonel Miles Quaritch
Joel Moore ... Norm Spellman (as Joel David Moore)
.........(and so on)





This is my coding..


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
string templine ;
string line;
ifstream myfile ("test");


while (getline (myfile,templine) )
line.append(templine);

char str [] = line ;
char delims[] = " as";
char *result = NULL;
result = strtok( str, delims );
while( result != NULL ) {
printf( result );
result = strtok( NULL, delims );
}




I keep getting the error saying ...
1
2

editmain.cpp.98:error: initializer fails to determine size of 'str'





what does this mean, and how can i be able to format my file in the way i want?
Last edited on
char str [] = line ;

This line makes no sense, char arrays are not strings, so you can't do this. I suggest you change your code to use only std::strings and not bother with char arrays.
Topic archived. No new replies allowed.