#include <unistd.h>
#include <cassert>
#include <fstream>
#include <iostream>
#include <memory>
ReadContent(std::string file) {
std::ifstream infile;
infile.open(file.data());
assert(infile.is_open());
std::string pre = "";
std::string s;
while (getline(infile, s)) {
pre += s + "\n";
}
infile.close();
return pre;
}
int main(){
char buff[250];
getcwd(buff, 250);
std::string current_path(buff);//获取此时的绝对路径 相对路径容易出错
std::string result= ReadContent(current_path+filename);
}
C++文件读取
最新推荐文章于 2024-08-03 18:36:56 发布