+ 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

23rd Oct 2016, 2:44 PM
samira
samira - avatar
6 Answers
+ 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
23rd Oct 2016, 6:45 PM
Tanel Helmik
Tanel Helmik - avatar
+ 1
if s.txt contains any value your program will run forever. please put a proper condition in while loop.
24th Oct 2016, 2:00 AM
Yash Raj
Yash Raj - avatar
+ 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.
24th Oct 2016, 2:00 AM
Evgeniy Dudnik
Evgeniy Dudnik - avatar
+ 1
Ű§ÙŠÙ‡ ۯۧ
14th Nov 2016, 1:45 PM
Nataly Bshara
Nataly Bshara - avatar
0
program of file prints the first letter of every line
14th Nov 2016, 1:58 PM
samira
samira - avatar
0
.
5th Feb 2018, 10:18 PM
Abdulali Miftah bin al-Faqih
Abdulali Miftah bin al-Faqih - avatar