does ios::ate truncates the file it the file already exist in c++.......
i tried and found that ios::ate truncates the file...
does ios::ate truncates the file it the file already exist in c++.......
i tried and found that ios::ate truncates the file...
If you want to append, use ios::app instead.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
yeah......i know that i can append using ios::app ..........
but my question is that will ios::ate truncates the file ...?
what is the use of using ios::ate if it truncates the file.....there is no use of appending if no data is present in file (ie.it gets truncates)
Well, it should not be truncating the file since that is supposed to be indicated by ios::trunc, not ios::ate.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
yes but i don't know why it is getting truncates.........any idea
Post your code and post your input file before and after running your program.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
hey i notice that in Turbo C++ the ios::ate is working as it should....ie it doesn't truncates the file.......
but at the same time in code::blocks Mingw compiler it is truncating the file
That goes down as the most uninformative response of the month to a request for code and relevant input files.
Odds are, you are using some magic value (e.g. or'ing with ios::ate) when opening the file. With MingW, that value causes truncation. With Turbo C++, you just got lucky that it didn't.
If you are going to persist in not providing useful information, and hoping that people will guess what your problem is, I suspect you will be disappointed.
I don't understand your refusal to post your code. My guess is that you used an ofstream, which then truncated the file when opening. If you used an fstream, ifstream, or added ios::in, perhaps this would not have happened. But I'm just guessing because of your obstinate refusal to post code that I can examine and perhaps test for myself.Originally Posted by Rohit Kumar
To show you that I practice what I preach, here's a program in which ios::ate is used and for which the file is not truncated, even when the program is compiled with gcc (which is what MinGW is a port of):
The content of hello.txt before and after running this program was the string "hello".Code:#include <fstream> int main() { std::fstream file("hello.txt", std::ios::ate); }
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)