Created
September 14, 2018 16:28
-
-
Save andrewcrabb/1247352a9a60282c290c791d5cf6b02c to your computer and use it in GitHub Desktop.
Boost filesystem intro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <boost/filesystem.hpp> | |
#include <boost/filesystem/path.hpp> | |
#include <boost/filesystem/fstream.hpp> | |
namespace bf = boost::filesystem; | |
int open_ostream(bf::ofstream &t_stream, bf::path t_path, std::ios_base::openmode t_mode) { | |
t_stream.open(t_path, t_mode); | |
if (!t_stream.is_open()) { | |
std::cerr << "Could not open output file " << t_path << std::endl; | |
return 1; | |
} | |
return 0; | |
} | |
int main(int argc, char **argv){ | |
std::string myname = "Andrew"; | |
std::cout << myname << std::endl; | |
bf::path my_path(argv[1]); | |
bf::path another_path; | |
std::cout << "another length: " << another_path.string().length() << std::endl; | |
std::cout << "raw: " << my_path << std::endl; | |
std::cout << "filename: " << my_path.filename() << std::endl; | |
std::cout << "stem: " << my_path.stem() << std::endl; | |
std::cout << "replace: " << my_path.replace_extension("foo") << std::endl; | |
std::cout << "raw now: " << my_path << std::endl; | |
bf::ofstream ofstr; | |
open_ostream(ofstr, my_path, std::ios::out); | |
ofstr << "Hello Andrew"; | |
// std::ofstream stdstream = open_stdstream(my_path.string()); | |
// stdstream << "Hello Andrew"; | |
std::string foo = "/foo/bar/baz.txt"; | |
bf::path other_path; | |
other_path = foo; | |
std::cout << "other: " << other_path << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment