0

What is the difference between ios::out or ios::trunc

Hey programmer i really dont understand what is the purpose of ios::trunc and one more thing why i cant use it like fstream ptr; ptr.open("ram.txt",ios::trunc);

1st Aug 2021, 1:29 PM
Atul Chourasiya
Atul Chourasiya - avatar
5 odpowiedzi
+ 2
ios::out writes over the original content of a file, and if what you put in a file is bigger than its contents, contents will be completely removed....
1st Aug 2021, 9:46 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 1
ios::trunc means that if the file is opened for output operations and it already existed, its previous content is deleted and replaced by the new one.
1st Aug 2021, 1:32 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 1
But ios::out starts to write from beginning without deleting previous content. Also ios::app could be used to append to the file
1st Aug 2021, 1:34 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 1
Aleksei Radchenkov thankyou now i get it.😊
2nd Aug 2021, 6:30 AM
Atul Chourasiya
Atul Chourasiya - avatar
0
Aleksei Radchenkov thanks bro but the issue is sometimes ios::out also delete previous content and i dont understand why is happening is there any reason behind it
1st Aug 2021, 2:48 PM
Atul Chourasiya
Atul Chourasiya - avatar