Hatena::ブログ(Diary)

C++でゲームプログラミング Twitter

2012-04-29

[][]fstream に Boost.Filesystem の path を渡す

Boost.Filesystem に path を受け取る fstream が定義されているらしいです。


[ソース]

#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>

int
main(int argc, char const* argv[]){
    namespace fs = boost::filesystem;
    
    fs::path exe = argv[0];

    fs::ifstream ifs(exe.parent_path()/"main.cpp");
    if( ifs.fail() ){
        std::cout << "Not found" << std::endl;
        return 1;
    }

    std::string line;
    while(std::getline(ifs, line)){
        std::cout << line << std::endl;
    }

    return 0;
}

[出力]

#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>

int
main(int argc, char const* argv[]){
    namespace fs = boost::filesystem;
    
    fs::path exe = argv[0];

    fs::ifstream ifs(exe.parent_path()/"main.cpp");
    if( ifs.fail() ){
        std::cout << "Not found" << std::endl;
        return 1;
    }

    std::string line;
    while(std::getline(ifs, line)){
        std::cout << line << std::endl;
    }

    return 0;
}

[boost]

  • ver 1.49.0

スパム対策のためのダミーです。もし見えても何も入力しないでください
ゲスト


画像認証

トラックバック - http://d.hatena.ne.jp/osyo-manga/20120429/1335704149