2016-07-23 28 views
0

これを投稿する前に前回チェックしても問題は解決しましたが、デバッグするのはちょっと悪くなりました(少なくとも初心者向け)。とにかく - 削除しても構いません。std :: ofstreamはファイルにstd :: stringを書き込むことができません

下のマークされた行で、ofstreamは単純な文字列を書き込めないようでした。テンプレートが問題であるように思われた:これはエラーになります

template <typename T> 
void appendVectorToCSV(const std::string& header, std::vector<T> row, 
     const std::string& outfilename){ 
    std::ofstream fout(outfilename); 
    fout << header;// << ","; /* The error line 80 */ 
    ... 

varUtils.hpp: In function ‘void appendVectorToCSV(std::string&, const std::vector<_RealType>&, const string&)’: 
varUtils.hpp:80:10: error: no match for ‘operator<<’ (operand types are ‘std::ofstream {aka std::basic_ofstream<char>}’ and ‘std::string {aka std::basic_string<char>}’) 
    fout << header;// << ","; 
     ^
varUtils.hpp:80:10: note: candidates are: 
... 
/usr/include/c++/4.8/complex:524:5: note: template<class _Tp, class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::complex<_Tp>&) 
    operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __x) 
    ^
/usr/include/c++/4.8/complex:524:5: note: template argument deduction/substitution failed: 
... 
varUtils.hpp:80:13: note: ‘std::ofstream {aka std::basic_ofstream<char>}’ is not derived from ‘std::basic_ostream<_CharT, _Traits>’ 
    fout << header;// << ","; 
      ^
+0

あなたの質問疑問を残した後、それを自分で答える必要があります。 – melpomene

+0

完了。確かに、それは読みやすいです。 – dasWesen

答えて

2

ので、解決策: 不足しているヘッダー。

#include <iostream> 

がすでにありましたが、ない

#include <fstream> 
関連する問題