mercredi 28 juillet 2021

Why does ofstream avoids the first 4 character while storing the value of the string?

Im using ofstream to get an input type string from user and put it in a file called question.txt. It doesnt show the first 4 characters in the file..I also tried without putting cout<<question and just getline(cin, question), If i do that, it doesnt let user put input at all

string question; 
cout<<"Enter Your Question: "<<endl;
cin>>question;
getline(cin, question);
cout<<question<<endl;
ofstream g("question.txt",ios::app);
g<<question<<endl;

This code above ignores the first 4 characters of the string and then prints the rest of the code.

string question; 
cout<<"Enter Your Question: "<<endl;
getline(cin, question);
cout<<question<<endl;
ofstream g("question.txt",ios::app);
g<<question<<endl;

This code above(without cin>>question) doesnt allow the user to input at all..this code is in an if else statement...when u put the same code somewhere else it works, but it doesnt work here for some reason

whole code paste bin link: https://pastebin.com/yQrzZXxJ code starts from line 83

Aucun commentaire:

Enregistrer un commentaire