前提・実現したいこと
こちらで紹介されていた2列のテキストファイルの読み込みをサンプルコードそのまま実行しようとしましたが、
コンパイルエラーとなりました。
エラーの解消方法を教えてください。
発生している問題・エラーメッセージ
'std::vector<std::pair<float,float>,std::allocator<_Ty>>::vector(const std::vector<_Ty,std::allocator<_Ty>> &)': 引数 1 を 'std::istream_iterator<std::pair<float,float>,char,std::char_traits<char>,ptrdiff_t>' から 'const std::allocator<_Ty> &' へ変換できません。
該当のソースコード
C++
1#include <iostream> 2#include <fstream> 3#include <iterator> 4#include <vector> 5 6int main() { 7 using namespace std; 8 vector<float> input((istream_iterator<float>(ifstream("datafile.dat"))), istream_iterator<float>()); 9 10 for (float item : input) { 11 cout << item << endl; 12 } 13}
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/02/02 00:29
2020/02/02 07:33