1 Star 0 Fork 0

小袖空空/cpp_dev_study

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
example.cpp 2.01 KB
一键复制 编辑 原始数据 按行查看 历史
小袖空空 提交于 2025-02-28 15:19 +08:00 . 2
#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
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/miGoCC/cpp_dev_study.git
git@gitee.com:miGoCC/cpp_dev_study.git
miGoCC
cpp_dev_study
cpp_dev_study
main

搜索帮助