clear data inside text file in c++

If you simply open the file for writing with the truncate-option, you’ll delete the content. std::ofstream ofs; ofs.open(“test.txt”, std::ofstream::out | std::ofstream::trunc); ofs.close(); http://www.cplusplus.com/reference/fstream/ofstream/open/

“Incomplete type not allowed ” when creating std::ofstream objects

As @Mgetz says, you probably forgot to #include <fstream>. The reason you didn’t get a not declared error and instead this incomplete type not allowed error has to do with what happens when there is a type that has been “forward declared”, but not yet fully defined. Look at this example: #include <iostream> struct Foo; … Read more

Getting filename (or path) from fstream

No, that is not possible, not at least in the Standard conformant implementation of the library. The fstream class doesn’t store the filename, and doesn’t provide any function for retrieving it. So one way to keep track of this information is to use std::map as: std::map<std::fstream*, std::string> stream_file_table; void f() { //when you open a … Read more

What is a stream in C++?

The term stream is an abstraction of a construct that allows you to send or receive an unknown number of bytes. The metaphor is a stream of water. You take the data as it comes, or send it as needed. Contrast this to an array, for example, which has a fixed, known length. Examples where … Read more

std::fstream buffering vs manual buffering (why 10x gain with manual buffering)?

This is basically due to function call overhead and indirection. The ofstream::write() method is inherited from ostream. That function is not inlined in libstdc++, which is the first source of overhead. Then ostream::write() has to call rdbuf()->sputn() to do the actual writing, which is a virtual function call. On top of that, libstdc++ redirects sputn() … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)