+ 2
I write this code but I need to get out from while loop when I need ... I tired do it
void put(char fileName[]){ fil s; fstream file(fileName, ios::out|ios::app); cout<<"\nEnter text and Enter space to get out: "; while (s.txt){ cin.getline(s.txt,255) ; if(s.txt !="n"){ cout<<"The first letter is : "<<s.txt[0]<<endl;} else break; } cout <<endl<< "Programed by : Samira aon"; while (s.txt){ file.write((char *)&s, sizeof(file)); } while((file.read((ch
6 odpowiedzi
+ 2
I don't understand all of this code but I see that you don't have a boolean operator in the while statement I would use cout <<s.txt to see what it stores and see if the if statement works checking for a string value
+ 1
if s.txt contains any value your program will run forever. please put a proper condition in while loop.
+ 1
you're trying to compare the whole line with "n". I guess you want to do something like "if ( s.txt[0] != 'n')" and you shouldn't use while loop for writing into a file.
+ 1
ايه دا
0
program of file prints the first letter of every line
0
.