In C++ it seems like every single time you open a file, the inner contents get deleted quickly. Is there a way to open the file at the end of the last character while keeping all contents within the file? I've been looking at something with the End of file function but I don't know if that's the right way to go. Any advice?
Kirielson 0 Light Poster
Recommended Answers
Jump to PostBy default, an output file opens in "truncate" mode which dumps all of the file's current contents and starts the file over. To prevent this, you need to use "append" mode.
Jump to PostThis is an output question, you can't write/output to an input file stream...
Jump to PostWriting is implied. The behavior described is default behavior for an output file stream (an ofstream).
When you open an output file, it's default mode is ios::out|ios::trunc. An input file stream (ifstream) doesn't behave like that, its default mode is ios::in. To prevent this default output stream behavior, you …
Jump to PostI know exactly what you are saying.But here.. you can go backwords too ;)).
#include <iostream> #include <fstream> int main () { std::ifstream in("asd.cpp",std::ios::in); in.seekg(in.tellg(),std::ios::end); int posit=in.tellg(); while (posit--) { in.seekg(posit); std::cout << (char) in.get(); } }
All 14 Replies
arkoenig 340 Practically a Master Poster
Fbody 682 Posting Maven Featured Poster
caut_baia 9 Posting Whiz
arkoenig 340 Practically a Master Poster
caut_baia 9 Posting Whiz
Fbody 682 Posting Maven Featured Poster
arkoenig 340 Practically a Master Poster
caut_baia 9 Posting Whiz
Fbody 682 Posting Maven Featured Poster
caut_baia 9 Posting Whiz
Fbody 682 Posting Maven Featured Poster
Kirielson 0 Light Poster
caut_baia 9 Posting Whiz
ankit1990rana 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.