Как отобразить имя файла с помощью outputfile
How do I add file name for outputFile at the end?
Что я уже пробовал:
#include <iostream> #include <ctime> #include <sys/types.h> #include <sys/stat.h> #include <cerrno> #include <cstring> #include <fstream> using namespace std; int main(int argc, char** argv ) {std::string x; std::ofstream outputFile; ifstream inFile; std::ifstream infile("Team.txt"); inFile.open("test.txt"); std::string line; while (std::getline(infile, line)) { std::cout << line << std::endl; } std::string dir=x; if (!inFile) { cout << "Unable to open file"; return(0); // terminate with error } while (inFile >> x) { dir=x; } inFile.close(); struct stat fileInfo; if (stat(dir.c_str(), &fileInfo) != 0) { // Use stat( ) to get the info std::cerr << "Error: " << strerror(errno) << '\n'; return(0); } outputFile << "Type: : "; if ((fileInfo.st_mode & S_IFMT) == S_IFDIR) { // From sys/types.h cout << "Directory\n"; } else { outputFile << "File\n"; } outputFile.open("program3data.txt"); outputFile << "Size : " << fileInfo.st_size << '\n'; // Size in bytes outputFile << "Device : " << (char)(fileInfo.st_dev + 'A') << '\n'; // Device number outputFile << "Created : " << std::ctime(&fileInfo.st_ctime); // Creation time outputFile << "Modified : " << std::ctime(&fileInfo.st_mtime); // Last mod time }