boost::iostreamsのエラーについて
Posted: 2011年8月08日(月) 22:15
皆様、お世話になっております。
現在、pipeで取得したデータをiostream経由で処理
(読み取りサイズなど指定などの利便性を考え)
しようと奮闘しております。boost::iostreamsが便利
であるため、こちらを利用しています。
ネット上にもそこそこ情報があり、色々と試しているのですが、
どうしてもうまくいきません。エラーを見ていると何か共通の
原因があるような気がしますが、もしかしたら、環境依存
(ディストリビューションの不備)の原因があるのではないか
とおもい、ご協力いただきたいと考えおります。
とりあえず、ネット上で紹介されているサンプルに関して、
動作させたいと思います。
http://ameblo.jp/topazbc/theme2-10007112994.html
を例と致します。(ただし、main文に関しては、私の方で
追加しています。)
こちらのコンパイル結果(fedora15,gcc-4.6.0,boost-1.46)は以下のとおりです。
In file included from stream.cpp:8:0:
/usr/include/boost/iostreams/device/file_descriptor.hpp: コンストラクタ ‘boost::iostreams::file_descriptor_source::file_descriptor_source(const Path&, std::ios_base::openmode) [with Path = int, std::ios_base::openmode = std::_Ios_Openmode]’ 内:
/usr/include/boost/iostreams/stream_buffer.hpp:96:1: instantiated from ‘boost::iostreams::stream_buffer<T, Tr, Alloc, Mode>::stream_buffer(const U0&, typename boost::disable_if<boost::is_same<U0, T> >::type*) [with U0 = int, T = boost::iostreams::file_descriptor_source, Tr = std::char_traits<char>, Alloc = std::allocator<char>, Mode = boost::iostreams::input_seekable, typename boost::disable_if<boost::is_same<U0, T> >::type = void]’
stream.cpp:24:21: instantiated from here
/usr/include/boost/iostreams/device/file_descriptor.hpp:194:7: エラー: ‘int’ から ‘const char*’ への無効な変換です [-fpermissive]
/usr/include/boost/iostreams/detail/path.hpp:47:5: エラー: initializing argument 1 of ‘boost::iostreams::detail::path::path(const char*)’ [-fpermissive]
ネット上のサンプルをいろいろ試してみましたが、
file_descriptor絡みでエラーが発生するケースが多い様です。
凡ミスでしたら申し訳ありませんが、原因がお分かりになる方
がいらっしゃりましたら、ご協力いただければ幸いです。
現在、pipeで取得したデータをiostream経由で処理
(読み取りサイズなど指定などの利便性を考え)
しようと奮闘しております。boost::iostreamsが便利
であるため、こちらを利用しています。
ネット上にもそこそこ情報があり、色々と試しているのですが、
どうしてもうまくいきません。エラーを見ていると何か共通の
原因があるような気がしますが、もしかしたら、環境依存
(ディストリビューションの不備)の原因があるのではないか
とおもい、ご協力いただきたいと考えおります。
とりあえず、ネット上で紹介されているサンプルに関して、
動作させたいと思います。
http://ameblo.jp/topazbc/theme2-10007112994.html
を例と致します。(ただし、main文に関しては、私の方で
追加しています。)
#include <cstdio>
#include <string>
#include <sstream>
#include <ostream>
#include <stdexcept>
#include <iostream>
#include <boost/iostreams/stream_buffer.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
int execcmd(const char* cmd, std::string& output)
{
// 子プロセスを起動
FILE* fp = popen(cmd, "r");
if (fp == 0) {
throw std::runtime_error(
std::string("popen(\"")
+ cmd + "\",\"r\")"
);
}
// 子プロセスの標準出力を取得
namespace io = boost::iostreams;
io::stream_buffer<io::file_descriptor_source>
sb(fileno(fp));
std::ostringstream oss;
oss << &sb;
oss.str().swap(output);
// 子プロセスの終了ステータスを取得
return pclose(fp);
}
int main(){
std::string command = "ls -la";
std::string output;
execcmd(command.c_str(), output);
std::cout<<"output :"<<output<<std::endl;
}
In file included from stream.cpp:8:0:
/usr/include/boost/iostreams/device/file_descriptor.hpp: コンストラクタ ‘boost::iostreams::file_descriptor_source::file_descriptor_source(const Path&, std::ios_base::openmode) [with Path = int, std::ios_base::openmode = std::_Ios_Openmode]’ 内:
/usr/include/boost/iostreams/stream_buffer.hpp:96:1: instantiated from ‘boost::iostreams::stream_buffer<T, Tr, Alloc, Mode>::stream_buffer(const U0&, typename boost::disable_if<boost::is_same<U0, T> >::type*) [with U0 = int, T = boost::iostreams::file_descriptor_source, Tr = std::char_traits<char>, Alloc = std::allocator<char>, Mode = boost::iostreams::input_seekable, typename boost::disable_if<boost::is_same<U0, T> >::type = void]’
stream.cpp:24:21: instantiated from here
/usr/include/boost/iostreams/device/file_descriptor.hpp:194:7: エラー: ‘int’ から ‘const char*’ への無効な変換です [-fpermissive]
/usr/include/boost/iostreams/detail/path.hpp:47:5: エラー: initializing argument 1 of ‘boost::iostreams::detail::path::path(const char*)’ [-fpermissive]
ネット上のサンプルをいろいろ試してみましたが、
file_descriptor絡みでエラーが発生するケースが多い様です。
凡ミスでしたら申し訳ありませんが、原因がお分かりになる方
がいらっしゃりましたら、ご協力いただければ幸いです。