#include #include #include #include // Additional files for file I/O #include #include #include // The following header may not be necessary //#include // Include Boost C++ libraries #include #include "boost/filesystem/operations.hpp" #include "boost/filesystem/path.hpp" #include "boost/progress.hpp" using namespace boost::filesystem; using namespace std; int main() { string my_str = "This is a string."; cout << my_str << endl; /* my_str = system("pwd"); my_str.append("\b\b\b\b\b\b\b\b extra"); cout << my_str << "a\b\b\b\b\b\b=" << endl; */ // Declare an output file stream. ofstream ofs; // Declare an input file stream. ifstream ifs; // Open the output file stream. string mystr = "read_me.text"; ofs.open(mystr.c_str(),ofstream::out); // Write some text to the output file stream. ofs << " Hello World." << endl; // Close the output file stream. ofs.close(); // Re-open the output file stream with a new name. mystr = "new.text"; ofs.open(mystr.c_str(),ofstream::out); // Write some text to the output file stream. ofs << " Overwritten." << endl; // Close the output file stream. ofs.close(); // Re-open the output file stream with the old name. mystr = "read_me.text"; ofs.open(mystr.c_str(),ofstream::out); // Write some text to the output file stream. ofs << " Finally Overwritten." << endl; // Close the output file stream. ofs.close(); // File that I want to determine the size of. mystr = "/home/arvind/projects/eda/rigatonista/benchmarks/tau2013_contest_library.v2.0.lb"; // Open input file stream. ifs.open(mystr.c_str(),ifstream::in); // Use C++ STL to determine the size of a file. // Get the initial position of the i/p file pointer. long initial = ifs.tellg(); // Bring the i/p file pointer to the end of the file. ifs.seekg(0, ios_base::end); // Get the final position of the i/p file pointer. long final = ifs.tellg(); cout << " ==Size is:::" << (final - initial) << "=" << endl; // Use POSIX/UNIX-based stat struct to determine the size of a file. struct stat st; if(0 == stat(mystr.c_str(), &st)) { cout << " ==POSIX/UNIX size:::" << st.st_size << "=" << endl; }else{ cout << " >>> File does not exist." << endl; } // Use Boost C++ Libraries to determine the size of a file. // Create a path for the file. path p(mystr); cout << p << "==" << endl; cout << " ==Boost C++ size:::" << file_size(mystr) << "=" << endl; // Close the input file stream. ifs.close(); return 0; }