#include <boost/lambda/lambda.hpp>#include <iostream>#include <iterator>#include <algorithm>#if defined(__LINUX__) || defined(__APPLE__) || defined(__unix__)#include<dirent.h>#elif defined(_WIN32) || defined(__WIN64__) || defined(__WINDOWS__)#include <direct.h> // _getcwd#endif#include <fstream>// 文件操作#include <string>// #include "simple_http_server.h"// #include <filesystem>namespace xk {//读写文件练习namespace file {// 获取当前工作目录// #include<dirent.h>// const std::string pwd = getCWD();// std::cout << pwd<< std::endl;std::string getCWD() {char *buffer;//也可以将buffer作为输出参数 #include<dirent.h>if ((buffer = getcwd(nullptr, 0)) == nullptr) {return {""};}return {buffer};}// 读取文件字符串// #include <fstream>// #include <string>// std::string filePath;// std::cout << "Enter file path: \n";// std::cin >> filePath;//// std::ifstream file(filePath);// if (!file) {// assert(file.is_open());// std::cerr << "Error opening file: " << filePath << std::endl;// return 1;// }// if (xk::file::read_file_content("/Users/xxkk/Documents/快捷开发文档/LINUX-install-mysql5.7Shell.txt", content))// std::cout << content << std::endl;bool read_file_content(const std::string &path, std::string &content) {std::ifstream file(path, std::ios::binary);if (!file.is_open()) {return false;}content.assign((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());file.close();return true;}}}int main() {// std::cout<< list_directory_contents(std::__fs::filesystem::current_path());return 0;}//c++ -I /Library/WebServer/Documents/boost_1_82_0 example.cpp -o example
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。